Django has floatformat template filter and it seem to use different approach in django.core.template.defaultfilters
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
"""
try:
f = float(text)
except ValueError:
return ''
m = f - int(f)
if m:
return '%.1f' % f
else:
return '%d' % int(f)
No comments:
Post a Comment