Skip to content

Conversation

@lovelydinosaur
Copy link
Contributor

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.

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

pySilver commented Aug 1, 2016

Thanks!

@lovelydinosaur
Copy link
Contributor 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.

3 participants