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

bcdiv

Description

The bcdiv of BCMath for PHP divides two arbitrary precision numbers.

Syntax

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

Parameters

num1

The dividend, as a string.

num2

The divisor, as a string.

scale

Sets 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 the result of the division, as a string; or null if num2 is 0.

Examples

1 · num1 num2

<?

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

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

var_dump($return);
string(1) "0"

2 · scale

<?

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

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

var_dump($return);
string(8) "0.246800"

3 · bcscale

<?

$scale = 6;

bcscale($scale);

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

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

var_dump($return);
string(8) "0.246800"