繁体   English   中英

Smarty-字符串到货币从逗号到点到逗号

[英]Smarty - String to Currency from comma to point to comma

我有以下字符串:

$betrag = 4,9

想要将其转换为货币:

4,90 €

有没有更好的方法如下:

{$betrag|replace:",":"."|string_format:"%.2f"|replace:".":","} €

好的解决方案是使用聪明的修饰符:

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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM