PHP uses number of integrated functions for conversion of number formats. The list of number converting functions is shown below.

The number format converting functions in PHP:

The number_format() function

The number_format() function is used to format a number grouped by thousands.

Syntax for number_format()

number_format (float $number[,int $decimals = 0]);

The number_format() function has one, two or four parameters. If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands. If two parameters are given, number will be formatted with decimals with a dot (".") in front, and a comma (",") between every group of thousands. If all four parameters are given, number will be formatted with decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.

Example with number_format() number converting function

 

›› go to examples ››