简体   繁体   English

如何在Fatfree框架中格式化货币

[英]How to format currency in fatfree framework

I need to format currency in fatfree framework but i cannot understand how to avoid decimal 我需要在无胖框架中格式化货币,但我不明白如何避免小数

with

 {0 ,number, currency}

i receive (of course) € 11.000,00 我收到(当然)€11.000,00

but with 但随着

{0 ,number, currency,int}

I have EUR 11.000,00 我有11.000,00欧元

any tips? 有小费吗?

The currency filter doesn't allow to define the number of decimals. currency过滤器不允许定义小数位数。

You can however create your own filter to fit exactly your needs. 但是,您可以创建自己的过滤器以完全满足您的需求。

Here's an example: 这是一个例子:

$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

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

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