File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -992,6 +992,9 @@ def quantize(self, value):
992
992
"""
993
993
Quantize the decimal value to the configured precision.
994
994
"""
995
+ if self .decimal_places is None :
996
+ return value
997
+
995
998
context = decimal .getcontext ().copy ()
996
999
context .prec = self .max_digits
997
1000
return value .quantize (
Original file line number Diff line number Diff line change @@ -894,6 +894,21 @@ class TestNoStringCoercionDecimalField(FieldValues):
894
894
)
895
895
896
896
897
+ class TestNoDecimalPlaces (FieldValues ):
898
+ valid_inputs = {
899
+ '0.12345' : Decimal ('0.12345' ),
900
+ }
901
+ invalid_inputs = {
902
+ '0.1234567' : ['Ensure that there are no more than 6 digits in total.' ]
903
+ }
904
+ outputs = {
905
+ '1.2345' : '1.2345' ,
906
+ '0' : '0' ,
907
+ '1.1' : '1.1' ,
908
+ }
909
+ field = serializers .DecimalField (max_digits = 6 , decimal_places = None )
910
+
911
+
897
912
# Date & time serializers...
898
913
899
914
class TestDateField (FieldValues ):
You can’t perform that action at this time.
0 commit comments