Alternative money_format in php on windows

2

When using money_format on windows, the function does not work because the function is only compatible with strfmon systems.

$number = 1234.56;

setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56

The above code works in the MAC and Linux environment, but not in windows. What alternative can I get?

    
asked by anonymous 04.05.2017 / 18:15

1 answer

1

According to this SO post in English , you can use the Intl extension . For example:

$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р.
    
04.05.2017 / 19:27