Change your Display for Different Currency Formats

Last Updated on: March 7, 2011

Lots of international websites now need to display prices in a number of different local currencies. As a web developer, it does not matter if your visitors are using US dollars, Euros, UK Pounds or Japanese Yen, you will want the currency to display properly for all of them. One of the best ways for you to do this is to use the number_format() PHP function to convert the output to the correct format.

{code type=php}
echo number_format($value, 2, ‘.’, ‘,’);

This will convert the value $total to the format $xx.yy and show two decimal places. This next example shows the user of the number_format() function to show a value in different currencies.

{code type=php}
$number = 1234.56;
// Use English notation (default)
$english_format_number = number_format($number);
// 1,235
// Show it in French format
$nombre_format_francais = number_format($number, 2, ‘,’, ‘ ‘);
// 1 234,56
$number = 1234.5678;
// And back to English without the thousand separator
$english_format_number = number_format($number, 2, ‘.’, ”);
// 1234.57

All you need to do now is to add some code that will convert your prices based on the current exchange rate and then you can display them in any currency format that your customers desire. Just remember to change the currency sign to that of the local currencies, whether £, $ or €, before you upset someone.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *