id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 3176 Patch: Make floatformat templatetag more generally useful Eric Floehr Adrian Holovaty "The floatformat tag is pretty specific: it formats to one decimal place, and doesn't put a decimal if the number only has zeros past the decimal (i.e. equivalent to an integer). I am developing an app with heavy display of floats, with different requirements including displaying different numbers of decimal places, and sometimes wanting to always display the decimal places. To solve the problem, I could create a custom tag, or make floatformat more generally useful. I chose the latter. floatformat in the default case works as it always has. However, floatformat now can take an argument which specifies the number of decimal places. If that number is positive, it will always display the decimal places. If that number is negative, it will only display decimal places if there aren't zeros in the decimal places (i.e. equivalent to an integer). For example, if num1 = 34.23234 and num2 = 34.00000: {{{ num1|floatformat results in 34.2 num2|floatformat is 34 num1|floatformat:3 is 34.232 num2|floatformat:3 is 34.000 num1|floatformat:-3 is 34.232 num2|floatformat:-3 is 34 }}} ""|floatformat"" and ""|floatformat:-1"" are functionally equivalent. I hope others find this enhancement useful. " enhancement closed Template system dev normal fixed templatetag floatformat templates Unreviewed 0 0 0 0 0 0