Decimal numbers are rounded to a specified number of decimal places

How to output a floating-point number rounded to 2 decimal places in Anqi CMS template?

floatformatThe filter can retain a floating-point number to 2 decimal places.Also, you can keep the specified number of decimal places.As in retaining 3 decimal places.Supports negative number digits, if a negative number is set, it is calculated from the last digit forward.

Usage Instructions

floatformatHow to use the filter:

{{ obj|floatformat:number }}

For example, you need to format34.23234To keep 3 decimal places, it can be written like this:

{{ 34.23234|floatformat:3 }}
# 显示结果
34.232

Here is an example demonstration

{{ 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