PHP – Displaying money with currency symbol

/ By Arjun / Published on August 7, 2015

You often have to display money numbers in business applications like eCommerce apps. So in general we fetch the value from the database and print it to the webpage with symbol concatenation as shown below code.

If you want to seriously internationalize your application, consider using a full-blown internationalization library like Zend Framework’s Zend_Locale and Zend_Currency.

PHP has money_format library function which can convert the number in to properly formatted with currency symbol.
Look at below code.

Output of the above code is as mentioned below.

The price US dollar is $3,030.25
The price UK pound is £220,220.25
The price Indian rupee is ₹ 2,50,250.75

You can see how money_format nicely set currency symbol and format the number with comma.
Important notice before money_format you have to call setlocale method and set ISO code for currency. money_format() doesn’t work on Windows and relies on setlocale() and it requires the installation of (arbitrarily named) locale packages on server side.

TIP : if you want to format only number you can use number_format() function something like this “echo "$ ".number_format($value, 2);

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
2 months ago

Its not working on windows

Would love your thoughts, please comment.x