mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Merge pull request #2948 from bimusiek/master
Added test ensuring DecimalField accepts `2E+2` as 200 and validates decimal place correctly.
This commit is contained in:
commit
ecb3ba5e1f
|
@ -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:
|
||||
|
|
|
@ -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."]),
|
||||
|
|
Loading…
Reference in New Issue
Block a user