Display Various Currencies in PHP

by Naveenkumar 2012-06-06 16:10:37


Hi,

Sometimes we must display a number as a money amount, but we can know what's the correct way to display each possible currency. Nevermind, PHP will do that for you:

$number = 1234.56;

// USA (USD 1,234.56)
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number);

// France (1 234,56 EUR)
setlocale(LC_MONETARY, 'fr_FR');
echo money_format('%i', $number);

// Brazil (1.234,56 BRL)
setlocale(LC_MONETARY, 'pt_BR');
echo money_format('%i', $number);

// Great Britain (GBP1,234.56)
setlocale(LC_MONETARY, 'en_GB');
echo money_format('%i', $number);

// Japan (JPY 1,235)
setlocale(LC_MONETARY, 'ja_JP');
echo money_format('%i', $number);
?>
815
like
0
dislike
0
mail
flag

You must LOGIN to add comments