Opened 6 years ago

Closed 6 years ago

#9565 closed (duplicate)

DecimalField damages decimals when saving

Reported by: mammique Owned by: kmtracey
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: UI/UX:

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 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to kmtracey
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 6 years ago by kmtracey

  • Resolution set to duplicate
  • Status changed from assigned to closed

#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