bcdivmod

(PHP 8 >= 8.4.0)

bcdivmodGet the quotient and modulus of an arbitrary precision number

Descrizione

bcdivmod(string $num1, string $num2, ?int $scale = null): array

Get the quotient and remainder of dividing num1 by num2.

Elenco dei parametri

num1

Il dividendo, come stringa.

num2

Il divisore, come stringa.

scale
Questo parametro viene utilizzato per impostare il numero di cifre dopo la virgola nel risultato. Se è null, verrà utilizzato il valore predefinito impostato con bcscale(), o in alternativa il valore della direttiva INI bcmath.scale.

Valori restituiti

Returns an indexed array where the first element is the quotient as a string and the second element is the remainder as a string.

_

_

Questa funzione genera un'eccezione DivisionByZeroError se num2 è 0.

Esempi

Example #1 bcdivmod() example

<?php
bcscale
(0);

[
$quot, $rem] = bcdivmod('5', '3');
echo
$quot; // 1
echo $rem; // 2

[$quot, $rem] = bcdivmod('5', '-3');
echo
$quot; // -1
echo $rem; // 2

[$quot, $rem] = bcdivmod('-5', '3');
echo
$quot; // -1
echo $rem; // -2

[$quot, $rem] = bcdivmod('-5', '-3');
echo
$quot; // 1
echo $rem; // -2
?>

Example #2 bcdivmod() with decimals

<?php
[$quot, $rem] = bcdivmod('5.7', '1.3', 1);
echo
$quot; // 4
echo $rem; // 0.5
?>

Vedere anche:

  • bcdiv() - Divide due numeri a precisione arbitraria
  • bcmod() - Ricava il modulo di un numero a precisione arbitraria
  • BcMath\Number::divmod()
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top