Open kynan opened 3 years ago
The relational operators cause valueOf
to be called on each Decimal, which returns string values which are then compared 'alphabetically', and '5' comes after '1'.
That does indeed make a lot of sense, thanks for the explanation! The joys of lexicographic comparison. And of course you can't have valueOf
return a numeric value as that may lose precision.
Worth mentioning this in the docs as a caveat?
As I did recently with big.js, in the next major release I may throw on calls to valueOf
to prevent accidental usage of Decimals with arithmetic and relational operators.
That's even better, as people don't read documentation :)
The following behavior is somewhat confusing:
I'm aware there's dedicated comparison operators, but why does "elementary" comparison give the wrong result in this case?