max_decimal_places in Decimal field are wrong calculated · Issue #2947 · encode/django-rest-framework (original) (raw)

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.