Ticket #5079: 5079.3.diff
File 5079.3.diff, 1.9 KB (added by , 17 years ago) |
---|
-
django/db/models/fields/__init__.py
686 686 if value < 0: 687 687 num_chars += 1 688 688 689 return u"%.*f" % (self.decimal_places, value) 689 if isinstance(value, decimal.Decimal): 690 return value.quantize(decimal.Decimal('.1')**self.decimal_places) 691 else: 692 return u"%.*f" % (self.decimal_places, value) 690 693 691 694 def get_db_prep_save(self, value): 692 695 if value is not None: -
tests/regressiontests/model_fields/tests.py
1 """ 1 2 3 from django.db import models 4 from decimal import Decimal 5 6 class DecimalTest(models.Model): 7 field = models.DecimalField(max_digits=40, decimal_places=25) 8 9 10 __test__ = {'API_TESTS': """ 2 11 >>> from django.db.models.fields import * 3 12 4 13 # DecimalField … … 15 24 Traceback (most recent call last): 16 25 ... 17 26 ValidationError: [u'This value must be a decimal number.'] 18 """ 27 28 # added after #5079 29 >>> b1 = DecimalTest(field=Decimal(".1")) 30 >>> b1.field 31 Decimal("0.1") 32 >>> b1.save() 33 >>> b1.field 34 Decimal("0.1") 35 36 # had to strip because mysql would return decimals with lots of 0000 at the end 37 >>> str(DecimalTest.objects.get(id=1).field).rstrip('0') 38 '0.1' 39 40 >>> b1 = DecimalTest(field=Decimal(".10000000000000000000000000000000005")) 41 >>> b1.field 42 Decimal("0.10000000000000000000000000000000005") 43 >>> b1.save() 44 >>> b1.field 45 Decimal("0.10000000000000000000000000000000005") 46 47 # had to strip because mysql would return decimals with lots of 0000 at the end 48 >>> str(DecimalTest.objects.get(id=2).field).rstrip('0') 49 '0.1' 50 """}