summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/core/defaultfilters.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/django/core/defaultfilters.py b/django/core/defaultfilters.py
index f6fd420572..f0e743500a 100644
--- a/django/core/defaultfilters.py
+++ b/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"