Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

Alternative to money_format() Function in PHP on Windows Platform

I am using the money_format() function in PHP, which gives the following error:

Fatal error: Call to undefined function 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.

Is there an equivalent PHP function available for Windows?

question from:https://stackoverflow.com/questions/6369887/alternative-to-money-format-function-in-php-on-windows-platform

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have the Intl extension, you can use

Example from Manual

$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."
";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."
";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."
";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."
";

Output

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...