Current Location: Home> Function Categories> number_format

number_format

Format a number in a thousand separator
Name:number_format
Category:String
Programming Language:php
One-line Description:Format numbers in thousands of groups.

Definition and usage

number_format() function formats numbers by grouping thousands of bits.

Note: This function supports one, two, or four parameters (not three).

Example

Example 1

Format numbers:

 <?php
echo number_format ( "5000000" ) . "<br>" ;
echo number_format ( "5000000" , 2 ) . "<br>" ;
echo number_format ( "5000000" , 2 , "," , "." ) ;
?>

Try it yourself

Example 2

You want to return a price: One parameter will round the number (formatted with no decimal places), and two parameters give the result you want:

 <?php
$num = 4999.9 ;
$formattedNum = number_format ( $num ) . "<br>" ;
echo $formattedNum ;
$formattedNum = number_format ( $num , 2 ) ;
echo $formattedNum ;
?>

Try it yourself

Similar Functions
Popular Articles