money_format
将数字格式化成货币字符串
money_format()
函数返回被格式化为货币字符串的字符串。
该函数在主字符串中的百分号(%)位置插入一个格式化的数字。
注释:money_format()
函数无法在 Windows 平台上工作。
提示:该函数常与 setlocale()
函数一起使用。
提示:如需查看所有可用的语言代码,请访问我们的语言代码参考手册。
en_US 国际格式:
<?php $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $number); ?>
以上代码的输出:
The price is USD 1,234.56
带 2 个小数的国际格式(德国):
<?php $number = 1234.56; setlocale(LC_MONETARY,"de_DE"); echo money_format("%.2n", $number); ?>
以上代码的输出:
1 234,56 EUR
负数,带有 () 指示负数的 US 国际格式,右侧精度为 2,并且 "*" 为填充字符:
<?php $number = -1234.5672; echo money_format("%=*(#10.2n",$number); ?>
以上代码的输出:
(******1234.57)