mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
DecimalFields should still be quantized even without coerce_to_string
This commit is contained in:
parent
040bfcc09c
commit
1e53eb0aa2
|
@ -486,9 +486,6 @@ class DecimalField(Field):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def to_primative(self, value):
|
def to_primative(self, value):
|
||||||
if not self.coerce_to_string:
|
|
||||||
return value
|
|
||||||
|
|
||||||
if isinstance(value, decimal.Decimal):
|
if isinstance(value, decimal.Decimal):
|
||||||
context = decimal.getcontext().copy()
|
context = decimal.getcontext().copy()
|
||||||
context.prec = self.max_digits
|
context.prec = self.max_digits
|
||||||
|
@ -496,7 +493,12 @@ class DecimalField(Field):
|
||||||
decimal.Decimal('.1') ** self.decimal_places,
|
decimal.Decimal('.1') ** self.decimal_places,
|
||||||
context=context
|
context=context
|
||||||
)
|
)
|
||||||
|
if not self.coerce_to_string:
|
||||||
|
return quantized
|
||||||
return '{0:f}'.format(quantized)
|
return '{0:f}'.format(quantized)
|
||||||
|
|
||||||
|
if not self.coerce_to_string:
|
||||||
|
return value
|
||||||
return '%.*f' % (self.max_decimal_places, value)
|
return '%.*f' % (self.max_decimal_places, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user