PHP number_format() Function

PHP number_format() Function

The number_format() function in PHP formats a number with grouped thousands. This function accepts one, two, or four parameters (not three):

Syntax

number_format ( float $number [, int $decimals ] )

            or

number_format ( float $number , int $decimals  , string $dec_point, string$thousands_sep )

Parameter

number(required)- This parameter represents the number to be formatted. If no parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator.

decimals(optional)- This parameter specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point.

decimalpoint(optional)- This parameter specifies what string to use for decimal point.

separator (optional)- This parameter specifies what string to use for thousands separator. Only the first character of separator is used.

Returns

This function returns a formatted version of number.

Example 1

 

Output

2,000,000
2,000,000.00
2.000.000,00 

Example 2

   

Output

Your number:8919.9
After using 'number_format()' function :
Formatted number: 8,920   

Example 3

   

Output

The number:100000000
The formated number :100,000,000.0000  

Example 4

   

Output

The number:100000000
The formated number :100#000#000.0000