diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 96fcc257a2..d8bb0a0179 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -782,7 +782,8 @@ def to_internal_value(self, data): 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 55e9aacc11..568e8d5e7a 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."]), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy