Differences in rounding when using `fromCents`
Closed this issue · 1 comments
Hello! Not sure if this is a bug or not, but I'm running into strange differences when using fromCents
on values where it would seemingly not matter, such as 0
.
Here's a quick reproduction:
currency(0).add(currency(7169, {fromCents: true})).multiply(20 / 100).format()
> $14.34
currency(0, {fromCents: true}).add(currency(7169, {fromCents: true})).multiply(20 / 100).format()
> $14.33
Would it be expected that currency(0)
would act differently than currency(0, {fromCents: true})
? Note the usage of 0
here is just an easy way to demonstrate the issue without using floats, currency(7169, {fromCents: true}).multiply(20 / 100).format()
and currency(71.69).multiply(20 / 100).format()
produce the same differing output, but that might be a little more understandable thanks to JS.
Definitely a bug!
71.69 * .2
is 14.338
and the problem is that from cents truncates partial cents. fromCents
should allow fractional values and round the same way that the normal method does.