I am trying to use the money_format()
function in PHP, but it 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) and also that the function has been removed from PHP 8.0.
Is there an equivalent PHP function available?
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")."\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";
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: