Home  • Programming • PHP

Display currencies with PHP

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:
<?php
$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);
?>

Comments 1


This post is useful to me
Copyright © 2025. Powered by Intellect Software Ltd