Documentation on bcdiv

bcdiv = Divide two arbitrary precision numbers

Divides the left_operand by the right_operand.

left_operand The left operand, as a string. right_operand The right operand, 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.

Usage, params, and more on bcdiv

string bcdiv ( string $left_operand , string $right_operand [, int $scale = 0 ] )

left_operand The left operand, as a string. right_operand The right operand, 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.

Returns the result of the division as a string, or NULL if right_operand is 0.

Notes and warnings on bcdiv

Other code examples of bcdiv being used

The custom bcdiv function listed at the top of this page produces very different results from bcdiv, as it rounds instead of truncating the result. Consider the following:

<?php

function bcdiv_cust( $first, $second, $scale = 0 )
{
   
$res = $first / $second;
    return
round( $res, $scale );
}

echo
bcdiv('1','2','0') . " vs. " bcdiv_cust('1','2','0');  // prints '0 vs. 1'

?>