Issue #1440 new

Wrong rounding with some decimals on round_decimal

Anderson Santos
created an issue

We are having a problem with wrong Balance Forward which is caused by the rounding on round_decimal function through trunc_decimal.

When trying the function like the following:

trunc_decimal(Decimal('58.9000010400'),2)

instead of rounding it only to 58.90, it's calculating 58.91

that's caused in the line 103 of satchmo_utils/numbers.py

decval=(decval//roundfactor*roundfactor)+roundby

I can't figure out how to improve this line. When I was thinking of writing a testcase for it I found out that there's already a failing test case with this issue but it's commented out on the test suit

https://bitbucket.org/chris1610/satchmo/src/210ec57ee9c6/satchmo/apps/satchmo_utils/tests.py#cl-48

I couldn't find the issue regarding this problem, not sure if there's one, but considering this line it's a known issue. Any perspective on solving this problem?

Comments (2)

  1. Alex Zagorodniuk

    i have the same issue. and i also traced it back to this line.

    decval=(decvalroundfactor*roundfactor)+roundby

    it's pretty bad, customers get charged extra cent... But i don't think anybody is going to fix it.. :/

  2. Chris Moffitt repo owner

    Could you take a look at replacing the instance of trunc_decimal with round_decimal?

    I think getting rid of trunc_decimal is probably the most sane approach but would appreciate it if some of the people with errors could give that a try.

  3. Log in to comment