How to use the bcmul function in PHP?
In PHP, the bcmul function is used for multiplying two arbitrary precision numbers. The syntax is as follows:
string bcmul ( string $left_operand , string $right_operand [, int $scale = 0 ] )
The $left_operand and $right_operand parameters are the two numbers to be multiplied, they must be passed as strings. The $scale parameter is optional and is used to specify the number of decimal places in the result, with a default value of 0 indicating no decimal places.
Here is an example using the bcmul function:
$num1 = "2.5";
$num2 = "3.14";
$result = bcmul($num1, $num2, 2);
echo $result; // 输出7.85
In the example above, we multiplied two numbers, “2.5” and “3.14”, and kept the result to two decimal places. The final output is “7.85”.