Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#403 closed defect (fixed)

[patch] floatformat error

Reported by: nesh <nesh [at] studioquattro [dot] co [dot] yu> Owned by: adrian
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:

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 Changed 10 years ago by Boffbowsh

  • Cc paul.bowsher@… added
  • Summary changed from floatformat error to [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 10 years ago by adrian

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

Fixed in [581].

comment:3 Changed 10 years ago by Boffbowsh

Thanks for getting the name right ;)

comment:4 Changed 10 years ago by adrian

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