我正在定制k2商店前端,我需要一些货币格式的帮助。
我的代码是:<span>Tax: <?php echo $item->tax ?></span>
<span>Price without tax: <?php echo $item->price; ?></span>
不知道为什么,但是这段代码输出:
Tax: 11
Price without TAX: 50.00000
我想输出:
Tax: 11,00 EUR
Price without tax: 50,00 EUR
我发现了一些在PHP中格式化值的提示,但我无法在我的情况下实现它。
如何使用php的money_format函数?在这种情况下,一个类似的帖子似乎有一个答案
setlocale(LC_MONETARY, 'nl_NL.UTF-8');
$amount = money_format('%(#1n', $amount);
echo $amount;
你可以把它放到像
这样的函数中function to_euro($input){
setlocale(LC_MONETARY, 'nl_NL.UTF-8');
return money_format('%(#1n', $input);
}
然后像
一样使用echo to_euro($item->tax);