1
php > var_dump(bccomp('-10.00001', '-10.0'));
int(0)

php > var_dump(bccomp('-10.00001', '-10.0', 17));
int(-1);

I don't get this at all. Isn't the entire point of the bcmath functions to allow you to do comparisons/arithmatic on floating point values as strings to avoid floating point issues?

Why even have a scale, shouldn't this just work properly every single time? What possible reason could someone want for having two unequal values be returned as equal?

1 Answers1

1

It does not require a scale. From the docs:

"The optional scale parameter is used to set the number of digits after the decimal place which will be used in the comparison."

There are some cases in which you would want a number with a certain number of decimal places to be equal to another number with a different number of decimal places, for a rather simplistic example:

10.44 = 10.4390
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • It doesn't require a scale to work properly unless your definition of "properly" is different than that of the PHP dev team. What is your definition? – Jay Blanchard Mar 15 '19 at 18:49
  • I can't figure out if you're a troll or you honestly believe what you wrote. Properly is comparing two numbers that aren't the same and returning that they aren't the same. The library literally has MATH in its name, math doesn't care about floating point, it's math, and proper math doesn't think 10.0001 and 10.0 are the same. –  Mar 17 '19 at 13:42