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:
Xavier Ordoquy 2015-05-29 11:52:33 +02:00
commit ecb3ba5e1f
2 changed files with 3 additions and 1 deletions

View File

@ -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:

View File

@ -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."]),