Change your Display for Different Currency Formats

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.


Leave a Reply

Your email address will not be published.

More Posts

How to use PHP Type Declarations

PHP has developed into a more strictly typed language in recent years. Type Declarations help with that and are a fairly new addition to PHP,


If you have come to JavaScript from a background in Java or C, then you will like the variation on the for loop. It is

Context Object Manipulation

One of the key concepts of JavaScript is the keyword this, which signifies the JavaScript context object. If you write an inner function, you can access

Polymorphic Functions

It is possible to define multiple functions with the same name in JavaScript, and the last one of those that you define will be the