From 91a283583cf17b9241bd1b9882783a8aedba4d8e Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Wed, 2 Nov 2005 19:01:27 +0000 Subject: [PATCH] Made floatformat filter not choke on non-floats git-svn-id: http://code.djangoproject.com/svn/django/trunk@1050 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/template/defaultfilters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/django/core/template/defaultfilters.py b/django/core/template/defaultfilters.py index 2604caf7f9..3a25add5e1 100644 --- a/django/core/template/defaultfilters.py +++ b/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