我正致力于将遗留系统从PEAR的i18nv2类升级到PHP的内置INTL库。当我指定#,##0.##
这样的模式并在NumberFormatter::format()
这样的数字上运行12345.1000
时,我得12,345.1
不应该保留尾随零?考虑到在许多语言环境中,十进制用逗号而不是十进制字符表示,是否有一种在事实之后添加尾随零的好方法?
用代码解释:
$n = new NumberFormatter('en_CA', NumberFormatter::PATTERN_DECIMAL, '#,##0.##');
echo $n->format(12345.10000);
答案 0 :(得分:2)
http://icu-project.org/apiref/icu4c/classDecimalFormatSymbols.html
Symbol Meaning
0 a digit
# a digit, zero shows as absent
所以:
$n = new NumberFormatter('en_CA', NumberFormatter::PATTERN_DECIMAL, '#,##0.00');
echo $n->format(12345.10000);
收率:
12,345.10