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');
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');
It outputs €45.00
(although I explicitly set to have a precision of zero).
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');
It outputs 45 €
.
Is this a bug?
Michael Gallego forgot to update this issue. Check out his bug report and the replies at php.net.
[2012-10-05 08:21 UTC] jpauli@email.com
I confirm this is an ICU bug in 4.4.x branch.
Consider upgrading libicu, 4.8.x gives correct result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With