PHP MySQL Tutorial
Learn PHP and MySQL

PHP Number Formats

PHP Number Formats

PHP's solution to formatting number is the number_format() function. This function take 4 arguments but only the first is mandatory.

The arguments are :

1. The number itself
2. Decimals
3. Decimal points
4. Thousand separators

Here are some examples :

1. number_format(123456) yields 123,456
2. number_format(123456, 2) yields 123,456.00
3. number_format(123456, 3) yields 123,456.000
4. number_format(123.456, 2) yields 123.46
5. number_format(123.456, 3) yields 123.456
6. number_format(123456, 2, ',', '.') yields 123.456,00
7. number_format(123456, 2, '.', ',') yields 123,456.00
8. number_format(123456.7, 2, '.', ',') yields 123,456.70


Note : this function CANNOT accept three arguments. Only one, two, or four. That means something like number_format(123456, 2, ',') is not a valid function call

Recent Comments

By: john9 Posted on 03-27-2015 7:05 AM
By: john9 Posted on 04-09-2015 10:06 AM
By: john9 Posted on 04-09-2015 10:11 AM
By: jenefee Posted on 07-11-2015 12:10 AM

Thanks such a lot with this fantastic new internet site. I’m terribly unemployed up to point out it to anyone. It makes American state therefore glad your Brobdingnagian understanding and knowledge have a brand new channel for attempting into the globe. http://judibola.co/

Powered by Community Server (Non-Commercial Edition), by Telligent Systems