Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecimalField accepts 2E+2 as 200 and validates decimal place correctly. #2948

Merged
merged 2 commits into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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