PHP number format mostly used

php number formats
php number formats

you can use PHP number Format simply to format a number with a grouped thousands numbering system.

The string number_format() function as a built-in function in PHP which is used to format a number with grouped thousands.It also supports one, two or four parameters (not three).

5 Quick examples on PHP number formats

Below are the examples

Quick examples on PHP formats



PARAMETERS: As mentioned above this function accepts four parameters and they are:

number: Set the number to format

decimals: How much decimals to display (function is optional)

decimalpoint: A string with the decimal separator.

sep: A string with the thousands separator. If this parameter is given, then all other parameters are required

More examples:


$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
// string number_format ($number, $decimals, $decimalpoint, $seperator)

// Enter the number you wish to format using decimals
// to set the number of decimal places
// You can replace the '.' with your own string
// with the decimalpoint parameter.
// With seperator, you can specify a string to be used
// to seperate thousands.

$num = 123456.789;
echo number_format($num); // 123,456
echo number_format($num, 4); // 123,456.7890
echo number_format($num, 4, '#'); // 123,456#7890
echo number_format($num, 5, '#', 'T'); // 123T456#78900


Please enter your comment!
Please enter your name here