What is the right way to compare 2 currency values?
pkozuchowski opened this issue · comments
I don't see any method like equals
to compare currency1.equals(currency2)
. What is the right way for comparing values?
Is c1.value === c2.value
safe considering floating point precision?
Please take under consideration implementing .equals, or .compare() method :)
Right now, there's no built in way to determine equality, but both .value
and .intValue
are safe for comparisons because the values are normalized.
var c1 = currency(2.52).subtract(.01);
var c2 = currency(2.50).add(.01);
c1.value === c2.value; // => true
There is a babel plugin that makes it so you can do straight up comparisons:
currency(1.23) === currency(1.23); // => true