-
Notifications
You must be signed in to change notification settings - Fork 145
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
Rounding precision #133
Comments
Currently, the bulk of the rounding happens inside of Lines 76 to 77 in 2eaefbe
Part of the issue at the moment, is only half cents are taken into consideration in this calculation. So |
1.2349 appears to be getting parsed internally as 123.49, and then rounded to 124, due to Is there harm in using I'll give you my use case – 7.35% sales tax on $81.97, is resulting in $6.03 of sales tax when the actual amount is $6.02. |
It's more of an issue of agnostically handling any arbitrary precision. Using |
I appreciate that immensely because as I was looking at the code and trying to think about this in higher and lower levels, I was coming to the same conclusion – I wish it could be solved in a more sound or proper way. If you want to discuss here or in a different issue, tag me. It's an interesting problem in general and I'm curious as to where it would land. |
Fortunately, |
What about this to round without errors ?
|
I bumped up the internal precision slightly to account for errors. Should handle a greater number of cases within reasonable values. |
I modified your unit test should default rounding when parsing to use
var round1 = currency(1.2349)
instead of current1.234
and that caused rouding to break (not half-up).The text was updated successfully, but these errors were encountered: