I ran into some problems using php class NumberFormatter. I want the rounded digits to be displayed without any decimals, and the decimal digits to be rounded with two decimals. i.e.
$fmt = new NumberFormatter('nl', NumberFormatter::CURRENCY); $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0); $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 2); var_dump($fmt->formatCurrency(15.15, 'EUR'));
As you can see, the last dump outputs 15,00 , but I expect 15 here. Whenever I use the "full" locale nl_NL instead of nl , the formatter behaves as expected, but I cannot use it because I only have the language available in my locale.
$fmt = new NumberFormatter('nl_NL', NumberFormatter::CURRENCY); $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0); $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 2); var_dump($fmt->formatCurrency(15.15, 'EUR'));
This seems like an error in NumberFormatter, but I really don't know how to fix this or figure out some other way around the problem. I would really appreciate any help.
php number-formatting
Bram gerritsen
source share