Opened 10 years ago

Closed 10 years ago

#9565 closed (duplicate)

DecimalField damages decimals when saving

Reported by: mammique Owned by: Karen Tracey
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: DecimalField precision decimal_places
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Decimals are damaged when using a big value for decimal_places.

Test realized with python-psycopg2 (2.0.6-3) under Ubuntu 8.04.1, on a fresh database and a new project:

class Test(models.Model):

    val = models.DecimalField(max_digits=30, decimal_places=18, default=0)
>>> import decimal
>>> Test(val=decimal.Decimal('12.9')).save()
>>> Test.objects.all()[0].val

Change History (2)

comment:1 Changed 10 years ago by Karen Tracey

Owner: changed from nobody to Karen Tracey
Status: newassigned
Triage Stage: UnreviewedAccepted

Ugh. django/db/backends/ format_number is using float format specifier to format the number to save to the db.

comment:2 Changed 10 years ago by Karen Tracey

Resolution: duplicate
Status: assignedclosed

#5079 already reported this. I'll take a look at fixing the problems noted in the patch that was already posted there.

Note: See TracTickets for help on using tickets.
Back to Top