aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index 20b8ffbf..a56ea96b 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -486,9 +486,6 @@ class DecimalField(Field):
return value
def to_primative(self, value):
- if not self.coerce_to_string:
- return value
-
if isinstance(value, decimal.Decimal):
context = decimal.getcontext().copy()
context.prec = self.max_digits
@@ -496,7 +493,12 @@ class DecimalField(Field):
decimal.Decimal('.1') ** self.decimal_places,
context=context
)
+ if not self.coerce_to_string:
+ return quantized
return '{0:f}'.format(quantized)
+
+ if not self.coerce_to_string:
+ return value
return '%.*f' % (self.max_decimal_places, value)