【问题标题】:How to format currency in fatfree framework如何在 fatfree 框架中格式化货币
【发布时间】:2017-04-04 15:24:10
【问题描述】:

我需要在 fatfree 框架中格式化货币但我不明白如何避免小数

 {0 ,number, currency}

我收到(当然)€ 11.000,00

但有

{0 ,number, currency,int}

我有 11.000,00 欧元

有什么建议吗?

【问题讨论】:

    标签: php currency fat-free-framework


    【解决方案1】:

    currency 过滤器不允许定义小数位数。

    不过,您可以create your own filter 完全满足您的需求。

    这是一个例子:

    $tpl=Template::instance();
    // declare a new filter named 'price'
    $tpl->filter('price',function($price,$decimals=0){
      return money_format('%.'.$decimals.'n',$price);
    });
    // test it:
    echo $tpl->resolve('{{ 12 | price }}'); // € 12
    echo $tpl->resolve('{{ 12.56 | price }}'); // € 13
    echo $tpl->resolve('{{ 12.56, 2 | price }}'); // € 12,56
    

    【讨论】:

      猜你喜欢
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多