How to output a floating-point number with 2 decimal places in the Anqi CMS template?
floatformat
The filter can output a floating-point number with 2 decimal places.Also, the specified number of decimal places can be retained.As for retaining decimal points to 3 places and so on.The function supports negative number of digits. If a negative number is set, it calculates from the last digit.
How to use
floatformat
How to use filters:
{{ obj|floatformat:number }}
For example, formatting is required34.23234
To retain 3 decimal places, you can write it like this:
{{ 34.23234|floatformat:3 }}
# 显示结果
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