bccomp
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5, PHP 7, PHP 8)
Compare two arbitrary precision numbers
Description
bccomp(string $num1, string $num2, int|null $scale = null): int
Compares num1 to num2 and returns the result of the comparison as an integer.
Return Values
Returns 0 if both operands are equal, 1 if num1 is greater than num2, -1 otherwise.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | scale is now nullable. |
Examples
bccomp() example
php
<?php
echo bccomp('1', '2') . "\n"; // -1
echo bccomp('1.00001', '1', 3); // 0
echo bccomp('1.00001', '1', 5); // 1
?>See Also
BcMath\Number::compare