CakePHP 3.6数字货币 [英] CakePHP 3.6 number currency
问题描述
我设置了
I18n::setLocale('en_EN');
和
I18n::setLocale('de_DE');
取决于语言切换。
I发现:
<?=$this->Number->currency($price, 'EUR', ['precision' => 0])?>
以德语显示
6.900.000€
6.900.000 €
和英语中的
6,900,000.00
€6,900,000.00
为什么不尊重精度?
有什么我可以做的吗?
Why the precision is not respected? Is there anything I can do?
推荐答案
首先,我认为 en_EN
是有效/受支持的语言环境,您宁愿使用 en_US
, en_GB
, en_CA
等。使用无效/不受支持的语言环境可能会使格式化程序崩溃。
First things first, I don't think en_EN
is a valid/supported locale, you'd rather use en_US
, en_GB
, en_CA
, etc. Using invalid/unsupported locales are likely to trip the formatter.
看起来还是一个可能的错误。 CakePHP在内部使用intl NumberFormatter
,似乎如果要格式化不是给定语言环境默认货币的货币(例如 EUR
(对于 en_US
语言环境),该货币必须作为格式器的属性应用,在应用精度之前,但是CakePHP仅将货币传递给 NumberFormatter :: formatCurrency()
方法。
That being said, this still looks like a possible bug. Internally CakePHP uses the intl NumberFormatter
, and it seems that if you want to format a currency that is not the default currency for the given locale (say EUR
for the en_US
locale), that currency must be applied as an attribute on the formatter, before applying the precision, CakePHP however only passes the currency to the NumberFormatter::formatCurrency()
method.
您可能要报告此情况作为问题 在GitHub上 。
You may want to report this as an issue over at GitHub.
另请参见 http:// php.net/manual/en/numberformatter.formatcurrency.php#114376
See also http://php.net/manual/en/numberformatter.formatcurrency.php#114376
这篇关于CakePHP 3.6数字货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!