bcdiv
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5, PHP 7, PHP 8)
Divide two arbitrary precision numbers
Description
bcdiv(string $num1, string $num2, int|null $scale = null): string
Divides num1 by num2.
Parameters
num1The dividend, as a string.
num2The divisor, as a string.
Return Values
Returns the result of the division as a string.
This function throws a DivisionByZeroError exception if num2 is 0.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | scale is now nullable. |
| 8.0.0 | Dividing by 0 now throws a DivisionByZeroError exception instead of returning null. |
Examples
bcdiv() example
php
<?php
echo bcdiv('105', '6.55957', 3); // 16.007
?>See Also
bcdivmod()bcmod()bcmul()BcMath\Number::div