在Smarty中更改数字格式以便显示

时间:2013-09-16 11:53:19

标签: php smarty

我想在smarty中格式化数字。任何人都可以帮我吗?

我在smarty变量中的含义是

31131

我想要展示的是

31,131

2 个答案:

答案 0 :(得分:3)

您可以在smarty中使用php number_format功能

{$number|number_format}

答案 1 :(得分:2)

只需使用PHP的内置函数number_format

$num = 31131;
$num = number_format($num);

echo $num;

输出:

31,131

Smarty方式:

首先定义您的号码:

$smarty->assign('number', 31131);

现在,在您的模板文件中,您可以执行以下操作:

{$number|number_format}

输出:

31,131

有关更多示例,请参阅documentation

Demo!