Django

Code

Ticket #4211 (closed: duplicate)

Opened 1 year ago

Last modified 1 year ago

FloatFields are not actually Floats

Reported by: David Cramer <dcramer@gmail.com> Assigned to: jacob
Milestone: Component: Uncategorized
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

FloatFields? should return a float() datatype so they can be used in comparison.

The issue arises when you want to compare data in the database, to data thats not yet in the database.

e.g.

float_field = FloatField?(decimal_places=2, max_digits=8)

a = MyModel?.objects.get(pk=1) In [57]: a.unknown3 Out[57]: Decimal("0.00")

In [58]: a.unknown3 == 0 Out[58]: True

In [59]: a.unknown3 == 0.0 Out[59]: False

In [60]: a.unknown3 == 0.00 Out[60]: False

This is misdirection and I believe one of the following should happen:

  • the data type should either be changed to a float
  • the data type should be comparable with a float
  • it should be relabeled DecimalField?

Attachments

Change History

05/03/07 17:04:50 changed by ubernostrum

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to duplicate.
  • needs_tests changed.
  • needs_docs changed.

A more comprehensive discussion is in #2365 (which proposes moving the current FloatField to a different name and implementing a new FloatField which guarantees a Python float type), so I'm closing this as a duplicate.


Add/Change #4211 (FloatFields are not actually Floats)




Change Properties
Action