PHP: number_format() function
PHP: Format a number with grouped thousands
The number_format() function is used to format a number (Floating number) with grouped thousands.
Version:
(PHP 4 and above)
Syntax:
number_format(number, decimals, dec_point, thousands_sep)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
number | The input number. | Required | Float |
decimals | Refer to the number of decimal points. | Optional | Integer |
dec_point | Refers the separator of decimal points. | Optional | String |
thousands_sep | Refers the thousands separator. | Optional | String |
Note: The function accepts one, two, or four parameters (not three).
Return value:
A formatted version of the number.
Value Type: String
Pictorial Presentation
Example:
<?php
$number=100000;
echo number_format($number).'<br>';
echo number_format($number, 2).'<br>';
echo number_format($number, 3).'<br>';
echo number_format($number, 2, ',', '.');
?>
Output:
100,000 100,000.00 100,000.000 100.000,00
View the example in the browser
See also
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/number_format.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics