scurker / currency.js

A javascript library for handling currencies

Home Page:https://currency.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Precision with fromCents results in incorrect values

hexagonal-sun opened this issue · comments

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

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!

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

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.