Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 5 additions and 4 deletions.
  1. +5 −4 django/core/defaultfilters.py
View
9 django/core/defaultfilters.py
@@ -23,14 +23,15 @@ def fix_ampersands(value, _):
def floatformat(text, _):
"""
- Displays a floating point number as 34.2 (with one decimal places) - but
+ Displays a floating point number as 34.2 (with one decimal place) - 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)
def linenumbers(value, _):
"Displays text with line numbers"
Please sign in to comment.
Something went wrong with that request. Please try again.