# PHP – How to divide two arbitrary precision numbers using bcdiv() function?

PHPServer Side ProgrammingProgramming

In PHP, bcdiv() math function is used to divide one arbitrary precision number from another number. The bcdiv() function takes two arbitrary precision numbers as strings and it gives the result as a division of two numbers after scaling the result to an identified precision. Or, we can say that the bcdiv() PHP function divides the dividend by the divisor.

string bcdiv($num_string1,$num_string2, $scaleVal) ## Parameters The bcmul() math function accepts three different parameters$num_string1, $num_string2 and$scaleVal.

• $num_string1 − It represents the dividend and it is the string type parameter. •$num_string2 − It represents the divisor, it is the string type parameter.

## Example 1− bcdiv() PHP function without using the $scaleVal parameter <?php // PHP program to illustrate bcdiv() function // two input numbers using arbitrary precision$num_string1 = "22.5552"; // Dividend numbers
$num_string2 = "5"; // divisor numbers$result = bcdiv($num_string1,$num_string2);
echo "Output without using Scale Value: ", $result; ?> ## Output Output without using Scale Value: 4 ## Example 2− bcdiv() PHP function using the scaleVal parameter Now, we will take the same input values with a scale value of 4 and check the output. <?php // PHP program to illustrate bcdiv() function // two input numbers using arbitrary precision$num_string1 = "22.5552"; // Dividend numbers
$num_string2 = "5"; // divisor numbers // using scale value 4$scaleVal = 4;

// two numbers without $scaleVal parameter$result = bcdiv($num_string1,$num_string2, $scaleVal); echo "Output with Scale Value is: ",$result;
?>
Output with Scale Value is: 4.5110