【问题标题】:Format (to currency) php syntax in K2 STORE在 K2 STORE 中格式化(到货币)php 语法
【发布时间】:2014-05-01 16:09:47
【问题描述】:

我正在定制 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 知识很差。

【问题讨论】:

    标签: php joomla joomla-k2


    【解决方案1】:

    使用php的money_format函数怎么样?在这种情况下,类似的SO post 似乎有答案

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      相关资源
      最近更新 更多