PHP NumberFormatter和货币,无法设置精度 [英] PHP NumberFormatter and Currency, can't set precision
问题描述
使用 NumberFormatter PHP类(来自国际扩展).但是我得到了一些奇怪的结果.在这里:
I want to set a precision of 0 when using the NumberFormatter PHP class (from Intl extension) with currency. However I've got some strange result. Here:
$numberFormatter = new NumberFormatter('en-US', NumberFormatter::CURRENCY);
$numberFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
echo $numberFormatter->formatCurrency('45', 'USD');
它输出$45
,这是我想要的.但是,如果我使用相同的设置将货币更改为EUR
:
It outputs $45
, which is what I want. However, if I change the currency to EUR
with the same settings:
echo $numberFormatter->formatCurrency('45', 'EUR');
它输出€45.00
(尽管我明确设置为精度为零).
It outputs €45.00
(although I explicitly set to have a precision of zero).
更奇怪的是,如果我将语言环境设置为fr-FR
,它将按预期输出数字:
Even more strange, if I set the locale to fr-FR
, it outputs the number as expected:
$numberFormatter = new NumberFormatter('fr-FR', NumberFormatter::CURRENCY);
$numberFormatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
echo $numberFormatter->formatCurrency('45', 'EUR');
它输出45 €
.
这是一个错误吗?
推荐答案
Michael Gallego忘记更新此问题.在php.net上查看他的错误报告和答复.
Michael Gallego forgot to update this issue. Check out his bug report and the replies at php.net.
- https://bugs.php.net/bug.php?id=63140
- http://bugs.icu-project.org/trac/ticket/7667
[2012-10-05 08:21 UTC] jpauli @ email.com
我确认这是4.4.x分支中的ICU错误.
考虑升级libicu,4.8.x会给出正确的结果
I confirm this is an ICU bug in 4.4.x branch.
Consider upgrading libicu, 4.8.x gives correct result
这篇关于PHP NumberFormatter和货币,无法设置精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!