Windows平台上PHP中money_format()函数的替代方法 [英] Alternative to money_format() Function in PHP on Windows Platform
本文介绍了Windows平台上PHP中money_format()函数的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在PHP中使用money_format()
函数,该函数会出现以下错误:
I am using the money_format()
function in PHP, which gives the following error:
Fatal error: Call to undefined function money_format()
有关此错误的搜索显示,仅当系统具有strfmon
功能时才定义功能money_format()
.例如,Windows没有,因此Windows中未定义money_format()
.
Searches about this error reveal that the function money_format()
is only defined if the system has strfmon
capabilities. For example, Windows does not, so money_format()
is undefined in Windows.
Windows是否有等效的PHP函数可用?
Is there an equivalent PHP function available for Windows?
推荐答案
If you have the Intl extension, you can use
- NumberFormatter :: formatCurrency -根据格式化程序规则.
- NumberFormatter::formatCurrency — Format a currency value according to the formatter rules.
手册中的示例
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
输出
1.234.567,89 €
1.234.567,89 RUR
1 234 567,89€
1 234 567,89р.
另请参阅我关于如何将格式化后的现金字符串解析回浮点数的答案:
Also see my answer on how to parse that formatted money string back into a float:
这篇关于Windows平台上PHP中money_format()函数的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文