Is it possible to format a number to 2 decimal places with Smarty PHP?
是否可以使用Smarty PHP将数字格式化为2位小数?
Thanks.
谢谢。
4 个解决方案
#1
41
string_format accepts sprintf formatting options:
string_format接受sprintf格式化选项:
{$number|string_format:"%.2f"}
#2
24
{$number|number_format:2}
is what you want
{$ number | number_format:2}就是你想要的
#3
10
{$number|round:"2"}
also works
{$ number | round:“2”}也有效
#4
1
To display 2 instead of 2.00 you can use : replace in Smarty PHP
要显示2而不是2.00,您可以使用:替换Smarty PHP
See below example -
见下面的例子 -
$number = 2.00
{$number|replace:'.00':''}
Output :- 2
Hope this helps.
希望这可以帮助。
#1
41
string_format accepts sprintf formatting options:
string_format接受sprintf格式化选项:
{$number|string_format:"%.2f"}
#2
24
{$number|number_format:2}
is what you want
{$ number | number_format:2}就是你想要的
#3
10
{$number|round:"2"}
also works
{$ number | round:“2”}也有效
#4
1
To display 2 instead of 2.00 you can use : replace in Smarty PHP
要显示2而不是2.00,您可以使用:替换Smarty PHP
See below example -
见下面的例子 -
$number = 2.00
{$number|replace:'.00':''}
Output :- 2
Hope this helps.
希望这可以帮助。