[PHP 4, PHP 5, PHP 7, PHP 8]
bccomp — Compare two arbitrary precision numbers
Description
bccomp[string $num1
, string $num2
, ?int $scale
= null
]:
int
Parameters
num1
The left operand, as a string.
num2
The right operand, as a string.
scale
The optional scale
parameter is used to set the number of digits after the decimal place which will be used in the comparison.
Return Values
Returns 0 if the two
operands are equal, 1 if the num1
is larger than the num2
, -1 otherwise.
Changelog
8.0.0 | scale is now nullable.
|
Examples
Example #1 bccomp[] example
Robert Lozyniak ¶
12 years ago
Beware that negative zero does not compare equal to positive zero.
aaugrin at gmail dot com ¶
4 years ago
BEWARE! left and right operand is string!! so number in E-notation like 9.012E-6 need to be converted with sprintf['%F'] to string
m dot kaczanowski at alianet dot pl ¶
13 years ago
Improvement of functions bcmax[] and bcmin[] originaly written by frank at booksku dot com
Anonymous ¶
17 years ago
Note that the above function defeats the purpose of BCMath functions, for it uses the 'conventional' < operator.
Instead, it should be:
Nitrogen ¶
13 years ago
I made this to compare an unlimited size of numbers..
This could be useful for those without the BCMath extension.
It allows decimals, and option $Scale parameter. If $Scale isn't specified, then it'll automatically adjust to the correct number of decimals to compare.