A number containing grouped thousands can be formatted using the built-in PHP function number_format(). If it is successful, it returns the formatted number; if it is unsuccessful, it displays "E WARNING".
Syntax
string number_format ( $number, $decimals, $decimalpoint, $separator )
Parameter : The four parameters that this function accepts are listed above and are discussed below.
$number: This option, which specifies the formatted number, is necessary. The number will be formatted without decimals and with the comma (,) serving as the thousands separator if no other specifications are specified.
$decimals: This parameter, which is optional, is used to specify decimals. The number will be formatted with a dot (.) as the decimal point if this parameter is specified.
$decimalpoint: The optional parameter $decimalpoint is used to provide the string to be used as the decimal point.
$separator : The $sep parameter, which is optional, is used to specify the string to be used as a thousands separator. All other parameters are necessary if this one is provided.
Return Value: In the event of success, it returns a formatted number.
Example
<?php
$number = "1000000";
echo number_format($number)."<br>";
echo number_format($number,2)."<br>";
echo number_format($number,2,",",".")
Output:
1,000,000
1,000,000.00
1.000.000,00
A number with grouped thousands is formatted using the number format() method.
Observation: This function accepts one, two, or four arguments (not three).