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

Quantize incoming digitals #4339

Merged
merged 1 commit into from
Aug 1, 2016
Merged

Quantize incoming digitals #4339

merged 1 commit into from
Aug 1, 2016

Conversation

tomchristie
Copy link
Member

DecimalField now quantizes incoming values, ensuring that the resulting value includes the correct representation.

Previous the value would be correct, but would not be associated with the precision used by the field, so eg...

>>> class ExampleSerializer(serializers.Serializer):
>>>     total_price = serializers.DecimalField(max_digits=5, decimal_places=2)
>>> serializer = ExampleSerializer(data={'total_price': '12'})
>>> assert serializers.is_valid()
>>> print serializer.validated_data['total_price']
12.00  # Now correctly represented. Previously would print 12.

Closes #4318.

@tomchristie tomchristie added this to the 3.4.2 Release milestone Aug 1, 2016
@tomchristie tomchristie merged commit 46a44e5 into master Aug 1, 2016
@tomchristie tomchristie deleted the quantize-digitals branch August 1, 2016 16:15
@pySilver
Copy link

pySilver commented Aug 1, 2016

Thanks!

@tomchristie
Copy link
Member Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants