HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

bcdivmod

Description

The bcdivmod of BCMath for PHP gets the quotient and modulus of an arbitrary precision number.

Syntax

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

Parameters

num1

The dividend, as a string.

num2

The divisor, as a string.

scale

This optional parameter is used to set the number of digits after the decimal place in the result.

If omitted, it will default to the scale set globally with the bcscale() function, or fallback to 0 if this has not been set.

Return

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

Examples

1 · num1 num2

<?

$num1 = "1.234";
$num2 = "5";

$return = bcdivmod($num1, $num2);

var_dump($return);
array(2) {
  [0]=>
  string(1) "0"
  [1]=>
  string(1) "1"
}

2 · scale

<?

$num1 = "1.234";
$num2 = "5";
$scale = 6;

$return = bcdivmod($num1, $num2, $scale);

var_dump($return);
array(2) {
  [0]=>
  string(1) "0"
  [1]=>
  string(8) "1.234000"
}

3 · bcscale

<?

$scale = 6;

bcscale($scale);

$num1 = "1.234";
$num2 = "5";

$return = bcdivmod($num1, $num2);

var_dump($return);
array(2) {
  [0]=>
  string(1) "0"
  [1]=>
  string(8) "1.234000"
}