Opened 9 years ago

Closed 9 years ago

#2366 closed defect (duplicate)

[patch] forms.FloatField is incompatible with models.FloatField

Reported by: adurdin@… Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This relates to #2365; models.FloatField uses decimal.Decimal objects, but forms.FloatField uses float() to convert its data to python objects. This causes a loss of accuracy when using high-precision decimals, e.g. models.FloatField(max_digits=30, decimal_places=18): 0.7 entered into the field in the admin interface will be saved as 0.699999999999999956.

Attachments (1)

formsFloatField.diff (2.2 KB) - added by adurdin@… 9 years ago.
Patch

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by adurdin@…

Patch

comment:1 Changed 9 years ago by anonymous

  • Summary changed from forms.FloatField is incompatible with models.FloatField to [patch] forms.FloatField is incompatible with models.FloatField

comment:2 Changed 9 years ago by anonymous

A note for when we get to this: If we wanted to go down this route, we would need to start shipping our own copy of the decimal module with Django. It is not in the standard Python library prior to Python 2.4 (and Django is implemented to work with Python 2.3).

comment:3 Changed 9 years ago by adurdin@…

Would there be any problem with limiting the decimal dependency to the DecimalField-related bits? That should be straightforward enough.

comment:4 Changed 9 years ago by adurdin@…

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

Closing this -- see #2365 instead, as they are very closely related.

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