bcdiv


php128 apg

DIVIDE two arbitrary precision numbers.





This function returns the ( $num1 / $num2 ) as STRING or
Warning on PHP 7.4.XX, or
Fatal error on PHP 8.0.XX,
if $num2 = 0.

If $scale is omited, this function will default to the scale set globally with the bcscale function, or fallback to 0 if this has not been set.



<?php

string bcmul 
string $num1 
                       
string $num2
                          ?
int $scale null )


where,

$num1 The dividend as STRING

$num2 
The divisor as STRING

$scale 
The number of decimal places 
                                      considered by this operation

?>
 

$num1


The dividend treated as STRING.



$num2


The divisor treated as STRING.



$scale


The number of decimal places to be considered.

This is nullable as of PHP 8.0.XX.



  1 EXERCISE   

<?php

$vl01a 
2020.106;

$vl01b 0.237;

$vl01c 0;

$sc01a 0;

$sc01b 10;

$bca01a bcdiv($vl01a$vl01b);

$bca01b1 bcdiv($vl01a$vl01b$sc01a);

$bca01b2 bcdiv($vl01a$vl01b$sc01b);

$bca01b3 bcdiv($vl01a$vl01c$sc01b);

echo 
'bcdiv( ' $vl01a ', ' $vl01b ' ) = ' $bca01a 
                                  
'<br>[ NO SCALE IS PROVIDED ]<br><br>'

echo 
'bcdiv( ' $vl01a ', ' $vl01b  ', ' $sc01a ' ) = ' $bca01b1 
                                  
'<br>[ SCALE = ' $sc01a ' ]<br><br>';

echo 
'bcdiv( ' $vl01a ', ' $vl01b  ', ' $sc01b ' ) = ' $bca01b2 
                                  
'<br> [ SCALE = ' $sc01b ' ]<br><br>';
                                  
echo 
'bcdiv( ' $vl01a ', ' $vl01c  ', ' $sc01b ' ) = ' $bca01b3 
                                  
'<br> [ SCALE = ' $sc01b ' ]<br><br>';

?>