number_format
该number_format过滤器格式的数字
参数:
decimal: 要显示的小数点数
decimal_point: 用于小数点的字符
thousand_sep: 用于千位分隔符的字符
举例:
{{ 9800.333|number_format(2, '.', ',') }}{# outputs : 9,800.33 #}
如果格式化负数的时候要注意要加括号
{{ -9800.333 |number_format(2, '.', ',') }} {# outputs : -9 #}
{{ (-9800.333)|number_format(2, '.', ',') }} {# outputs : -9,800.33 #}
本文详细介绍如何使用number_format过滤器来格式化数字,包括设置小数点数量、小数点字符和千位分隔符,以及如何正确处理负数格式化。
968

被折叠的 条评论
为什么被折叠?



