Opened 16 years ago

Closed 16 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

Description

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
Decimal("12.900000000000000355")

Change History (2)

comment:1 by Karen Tracey, 16 years ago

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

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

comment:2 by Karen Tracey, 16 years ago

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