currency.js
currency.js copied to clipboard
Unexpected results with arithmatic when using fromCents
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.
This was discussed on this issue: https://github.com/scurker/currency.js/issues/260#issuecomment-659675669
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.