我有以下字符串:
$betrag = 4,9
想要将其转换为货币:
4,90 €
是否有更好的方法:
{$betrag|replace:",":"."|string_format:"%.2f"|replace:".":","} €
好的解决方案是使用smarty修饰符:
function smarty_modifier_num2front($string, $precision = 2)
{
// here you can use your own filter by call some class (or direct php code)
return \lib\Numeric::front($string, $precision);
}
以下函数应位于smarty插件目录中,在本例中名为'modifier.num2front.php'
在模板中,你使用这样:
{$betrag|num2front}