Alternative money_format in php in windows

Asked

Viewed 200 times

2

When using money_format in 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 code above works in MAC and Linux environment, but not in windows. What alternative can I arrange?

1 answer

1

According to this OS 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";

Exit:

1.234.567,89 €
1.234.567,89 RUR
1 234 567,89€
1 234 567,89р.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.