Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#403 closed defect (fixed)

[patch] floatformat error

Reported by: nesh <nesh [at] studioquattro [dot] co [dot] yu> Owned by: Adrian Holovaty
Component: Template system Version:
Severity: normal Keywords:
Cc: paul.bowsher@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When using floatformat with FloatField (MySQL)]:

  File "/Users/nesh/devel/django/django/core/", line 411, in resolve_variable_with_filters
    obj = registered_filters[name][0](obj, arg)

  File "/Users/nesh/devel/django/django/core/", line 31, in floatformat
    if text - int(text) < 0.1:

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/", line 636, in __cmp__
    other = _convert_other(other)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/", line 2863, in _convert_other
    raise TypeError, "You can interact Decimal only with int, long or Decimal data types."

TypeError: You can interact Decimal only with int, long or Decimal data types.

Change History (4)

comment:1 Changed 12 years ago by Boffbowsh

Cc: paul.bowsher@… added
Summary: floatformat error[patch] floatformat error

Excuse the partial diff, i've also got the file half-modified for another ticket

 def floatformat(text, _):
     Displays a floating point number as 34.2 (with one decimal places) - but
     only if there's a point to be displayed
+    from math import modf
     if not text:
         return ''
-    if text - int(text) < 0.1:
-        return int(text)
-    return "%.1f" % text
+    if modf(float(text))[0] < 0.1:
+        return text
+    return "%.1f" % float(text)

comment:2 Changed 12 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

Fixed in [581].

comment:3 Changed 11 years ago by Boffbowsh

Thanks for getting the name right ;)

comment:4 Changed 11 years ago by Adrian Holovaty

Ah, sorry about the name -- usually I just look at whoever reported the ticket.

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