-
Notifications
You must be signed in to change notification settings - Fork 9
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
Money.fromDecimal is subject to floating point calculation errors #1
Comments
Hi @anujbiyani |
In case it helps, here's the
It's a Typescript version of https://stackoverflow.com/questions/15762768/javascript-math-round-to-two-decimal-places/15762794#15762794 |
Terribly sorry for the delay, I've been really busy lately. An update will be plublished by monday. |
No worries, thanks for the update! Let me know if I can help. |
@anujbiyani The issue should be fixed now. Basically, we now always use the rounder function in Here is the commit Let me know if you think another approach would be better suited to fix this problem. Thanks again for signaling the issue, really appreciated! :) |
Looks great! Thank you. |
These lines are subject to floating point errors:
For example:
The result of this calculation is assumed to be an integer:
but because of floating point calculation inaccuracies that's not always the case.
It's easy to workaround this issue by passing a
rounder
toMath.fromDecimal
, but I feel like this issue is better fixed by ts-money itself, e.g. by using a default rounder.Would you be open to a PR to address this?
The text was updated successfully, but these errors were encountered: