Browse files

Made floatformat filter not choke on non-floats

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1050 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 27efe14 commit 91a283583cf17b9241bd1b9882783a8aedba4d8e @jacobian jacobian committed Nov 2, 2005
Showing with 4 additions and 1 deletion.
  1. +4 −1 django/core/template/defaultfilters.py
View
5 django/core/template/defaultfilters.py
@@ -27,7 +27,10 @@ def floatformat(text, _):
Displays a floating point number as 34.2 (with one decimal place) -- but
only if there's a point to be displayed
"""
- f = float(text)
+ try:
+ f = float(text)
+ except ValueError:
+ return ''
m = f - int(f)
if m:
return '%.1f' % f

0 comments on commit 91a2835

Please sign in to comment.