Skip to content

max_decimal_places in Decimal field are wrong calculated #2947

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

Closed
bimusiek opened this issue May 18, 2015 · 2 comments · Fixed by #2948
Closed

max_decimal_places in Decimal field are wrong calculated #2947

bimusiek opened this issue May 18, 2015 · 2 comments · Fixed by #2948
Milestone

Comments

@bimusiek
Copy link
Contributor

We got an issue when number is formatted as decimal.Decimal('2E+9').

How DecimalField counts decimals:

    sign, digittuple, exponent = value.as_tuple()
    decimals = abs(exponent)

However result of decimal.Decimal('2E+9').as_tuple()[2] is 9, which is ok, but there are no decimal places in this number.

My solution is to not do abs and instead multiply by -1.

I can prepare PR tonight if you think it is valid.

@tomchristie
Copy link
Member

So things that would help here:

  • Any comparisons between what happens in Django core and what we do (if that's possible/relevant?)
  • One or two example cases (In particular pull requests with failing test cases), and expected input/output values.

@bimusiek
Copy link
Contributor Author

@tomchristie I added PR with example and solution.
Basically we get really huge number, then normalize it with .normalize() which resulted in having 2E+9 which resulted in ValidationError :)

Hope PR is valid!

@xordoquy xordoquy added this to the 3.1.3 Release milestone Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants