I'm working on upgrading a legacy system from PEAR's i18nv2 class to PHP's built-in INTL library. When I specify a pattern like #,##0.##
and run NumberFormatter::format()
on a number like 12345.1000
I get 12,345.1
shouldn't trailing zeroes be preserved? Is there a good way to add trailing zeroes after the fact taking into consideration that in many locales, a decimal is represented by a comma instead of the decimal character?
Explained with code:
$n = new NumberFormatter('en_CA', NumberFormatter::PATTERN_DECIMAL, '#,##0.##');
echo $n->format(12345.10000);
http://icu-project.org/apiref/icu4c/classDecimalFormatSymbols.html
Symbol Meaning
0 a digit
# a digit, zero shows as absent
So:
$n = new NumberFormatter('en_CA', NumberFormatter::PATTERN_DECIMAL, '#,##0.00');
echo $n->format(12345.10000);
Yields:
12,345.10
来源:https://stackoverflow.com/questions/36895787/preserve-trailing-zeroes-using-numberformatter-in-php