Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision with fromCents results in incorrect values #318

Open
hexagonal-sun opened this issue May 18, 2021 · 3 comments
Open

Precision with fromCents results in incorrect values #318

hexagonal-sun opened this issue May 18, 2021 · 3 comments

Comments

@hexagonal-sun
Copy link

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
Copy link
Author

hexagonal-sun commented May 18, 2021

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 scurker added bug and removed bug labels May 18, 2021
@scurker
Copy link
Owner

scurker commented May 19, 2021

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants