Precision with fromCents results in incorrect values
hexagonal-sun opened this issue · 3 comments
hexagonal-sun commented
Hi @scurker
I'm using fromCents
with a precison
option and I'm getting unexpected results:
> currency(123, {fromCents: true, precision: 4}).format()
'$0.0123'
I would have expected $1.2300
.
Thanks,
Matt
hexagonal-sun commented
Additionally, I would have also expected to be able to add decimal amounts to cents:
currency(123.98, {fromCents: true, precision: 4}).format()
Which would yield: $1.2398
, I'm currently getting $0.0124
. Thanks!
scurker commented
This is expected behavior.
currency(1, { fromCents: true }) // => $0.01
currency(123, { fromCents: true }) // => $1.23
currency(123, { fromCents: true, precision: 3 }) // => $0.123
hexagonal-sun commented
In that case, I'd suggest that the name fronCents
is misleading. I'd have thought that even with a higher precision, 123 cents would still result in $1.23
.