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

Unexpected results with arithmatic when using fromCents #319

Open
hexagonal-sun opened this issue May 18, 2021 · 1 comment
Open

Unexpected results with arithmatic when using fromCents #319

hexagonal-sun opened this issue May 18, 2021 · 1 comment

Comments

@hexagonal-sun
Copy link

Hi @scurker ,

I've found some inconsistencies when applying arithmetic after using
fromCents:

> c(451, {fromCents: true}).subtract(1).format()
'$4.50'

I would have expected the value to be $3.50; the same is also true for add. Perhaps this is expected behavior and creating a currency object using fromCents means that arithmetic performed is in cent amounts rather than
dollar amounts. If that's the case, I'd say that the name fromCents is misleading as it implies you get a regular currency object, except that the initial value is converted from cents; there's nothing to indicate that arithmatic is done in cent values.

Thanks.

@scurker
Copy link
Owner

scurker commented May 18, 2021

This was discussed on this issue: #260 (comment)

The currency object inherits all of the options passed into the initial function. I would think the opposite behavior would be more confusing, as I would think all of your nominal values would be similar - but I haven't actively used fromCents much myself.

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

No branches or pull requests

2 participants