Django

Code

Changeset 581

Show
Ignore:
Timestamp:
08/31/05 11:45:10 (3 years ago)
Author:
adrian
Message:

Fixed #403 -- Fixed bug in floatformat template filter. Thanks, nesh

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/defaultfilters.py

    r538 r581  
    2424def floatformat(text, _): 
    2525    """ 
    26     Displays a floating point number as 34.2 (with one decimal places) - but 
     26    Displays a floating point number as 34.2 (with one decimal place) - but 
    2727    only if there's a point to be displayed 
    2828    """ 
     29    from math import modf 
    2930    if not text: 
    3031        return '' 
    31     if text - int(text) < 0.1: 
    32         return int(text) 
    33     return "%.1f" % text 
     32    if modf(float(text))[0] < 0.1: 
     33        return text 
     34    return "%.1f" % float(text) 
    3435 
    3536def linenumbers(value, _):