Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9635ac07a5ee9a1ff54ebcfb08b48622356b0326 1 parent cb6aa10
Adrian Holovaty authored

Showing 1 changed file with 5 additions and 4 deletions. Show diff stats Hide diff stats

  1. 9  django/core/defaultfilters.py
9  django/core/defaultfilters.py
@@ -23,14 +23,15 @@ def fix_ampersands(value, _):
23 23
 
24 24
 def floatformat(text, _):
25 25
     """
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
27 27
     only if there's a point to be displayed
28 28
     """
  29
+    from math import modf
29 30
     if not text:
30 31
         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)
34 35
 
35 36
 def linenumbers(value, _):
36 37
     "Displays text with line numbers"

0 notes on commit 9635ac0

Please sign in to comment.
Something went wrong with that request. Please try again.