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
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.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.