Opened 19 years ago

Closed 19 years ago

Last modified 19 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: no UI/UX: no

Description

When using floatformat with FloatField (MySQL)]:
R545

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

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

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

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/decimal.py", 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 by Boffbowsh, 19 years ago

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 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [581].

comment:3 by Boffbowsh, 19 years ago

Thanks for getting the name right ;)

comment:4 by Adrian Holovaty, 19 years ago

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