HOW TO FORMAT NUMBERS IN PHP USING THE number_format() FUNCTION
Using the number_format() function, you can control how PHP displays your numbers on screen. The general format of use of the functions is as follows:
number_format (number, decimals , dec_point , thousands_sep);
number: The actual number being formatted.
decimals: How many decimal places.
dec_point: What character to use as separator. Default is decimal point (.).
thousands_sep: What character to use as separator for thousands. Default is comma (,).
Example:
$number= 123456789;
$newNumber=number_format ($number, 2 , "." , ",");
echo $newNumber; // outputs 123,456,789.00
Simple example using just 2 parameters ie. the number to format and how many decimal places:
$number= 123;
$newNumber=number_format ($number, 2);
echo $newNumber; //outputs 123.00
|