Code

Opened 7 years ago

Closed 7 years ago

#4211 closed (duplicate)

FloatFields are not actually Floats

Reported by: David Cramer <dcramer@…> Owned by: jacob
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (1)

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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 Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.