PHP MySQL Tutorial
Learn PHP and MySQL

PHP Number Formats

Page Details

Published by:
admin
on 12-20-2008
This page has not yet been rated

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

Leave the first comment for this page.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems