问题
Is it possible to format a number to 2 decimal places with Smarty PHP?
Thanks.
回答1:
string_format accepts sprintf formatting options:
{$number|string_format:"%.2f"}
回答2:
{$number|number_format:2}
is what you want
回答3:
{$number|round:"2"}
also works
回答4:
To display 2 instead of 2.00 you can use : replace in Smarty PHP
See below example -
$number = 2.00
{$number|replace:'.00':''}
Output :- 2
Hope this helps.
来源:https://stackoverflow.com/questions/2409110/is-it-possible-to-format-a-number-to-2-decimal-places-with-smarty-php