Floating point numbers retain the specified decimal point

How to keep a floating point number output in Anqi CMS template?

floatformatThe filter can retain a floating point number with 2 decimal output. You can also keep other decimal points specified. For example, keep 3 decimal places, etc. At the same time, negative digits are supported. If the negative number is set, the calculation is forward from the last digit.

How to use

floatformatHow to use filters:

{{ obj|floatformat:number }}

For example, formatting is required34.23234Keep 3 decimal places, you can write this:

{{ 34.23234|floatformat:3 }}
# Show result
34.232

Sample Demo

{{ 34.23234|floatformat }}
{{ 34.00000|floatformat }}
{{ 34.26000|floatformat }}
{{ "34.23234"|floatformat }}
{{ "34.00000"|floatformat }}
{{ "34.26000"|floatformat }}
{{ 34.23234|floatformat:3 }}
{{ 34.00000|floatformat:3 }}
{{ 34.26000|floatformat:3 }}
{{ 34.23234|floatformat:"0" }}
{{ 34.00000|floatformat:"0" }}
{{ 39.56000|floatformat:"0" }}
{{ 34.23234|floatformat:"-3" }}
{{ 34.00000|floatformat:"-3" }}
{{ 34.26000|floatformat:"-3" }}
# 显示结果
34.2
34
34.3
34.2
34
34.3
34.232
34.000
34.260
34
34
40
34.232
34
34.260