Made floatformat filter not choke on non-floats

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1050 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2005-11-02 19:01:27 +00:00
parent 27efe14c54
commit 91a283583c
1 changed files with 4 additions and 1 deletions

View File

@ -27,7 +27,10 @@ def floatformat(text, _):
Displays a floating point number as 34.2 (with one decimal place) -- but Displays a floating point number as 34.2 (with one decimal place) -- but
only if there's a point to be displayed only if there's a point to be displayed
""" """
f = float(text) try:
f = float(text)
except ValueError:
return ''
m = f - int(f) m = f - int(f)
if m: if m:
return '%.1f' % f return '%.1f' % f