Display Currencies In PHP - Code

by Naveenkumar 2012-08-20 10:59:38

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);
?>
896
like
0
dislike
0
mail
flag

You must LOGIN to add comments