diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 96fcc257a..d8bb0a017 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -782,7 +782,8 @@ class DecimalField(Field): self.fail('invalid') sign, digittuple, exponent = value.as_tuple() - decimals = abs(exponent) + decimals = exponent * decimal.Decimal(-1) if exponent < 0 else 0 + # digittuple doesn't include any leading zeros. digits = len(digittuple) if decimals > digits: diff --git a/tests/test_fields.py b/tests/test_fields.py index 55e9aacc1..568e8d5e7 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -647,6 +647,7 @@ class TestDecimalField(FieldValues): 0: Decimal('0'), 12.3: Decimal('12.3'), 0.1: Decimal('0.1'), + '2E+2': Decimal('200'), } invalid_inputs = ( ('abc', ["A valid number is required."]),