Skip to content

Commit

Permalink
Merge pull request #2948 from bimusiek/master
Browse files Browse the repository at this point in the history
Added test ensuring DecimalField accepts `2E+2` as 200 and validates decimal place correctly.
  • Loading branch information
xordoquy committed May 29, 2015
2 parents 6634ce0 + e8c226c commit ecb3ba5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."]),
Expand Down

0 comments on commit ecb3ba5

Please sign in to comment.