number_format
Function • Params and return types changed in PHP 8.0
Format a number with grouped thousands.
number_format Function synopsis
number_format(
float $num,
int $decimals = 0,
?string $decimal_separator = ".",
?string $thousands_separator = ","
): string
Parameters
$num
Typefloat
The number being formatted.
$decimals
OptionalTypeintDefault value0
Sets the number of decimal digits.
If 0, the $decimal_separator is
omitted from the return value.
As of PHP 8.3.0, when the value is negative, $num
is rounded to $decimals significant digits before
the decimal point.
Prior to PHP 8.3.0, negative values were ignored and handled the
same as 0.
$decimal_separator
OptionalType?stringDefault value"."
Sets the separator for the decimal point.
$thousands_separator
OptionalType?stringDefault value","
Sets the thousands separator.
Return value
Typestring
A formatted version of $num.
Changes to the number_format Function
PHP 8.0
- Return type added:
string - Parameter name of parameter #1 changed:
$numberto$num - Parameter type added for parameter #1 (
$num):float - Parameter name of parameter #2 changed:
$num_decimal_placesto$decimals - Parameter type added for parameter #2 (
$decimals):int - Parameter default value added for position #2 (
$decimals):0 - Parameter name of parameter #3 changed:
$dec_separatorto$decimal_separator - Parameter type added for parameter #3 (
$decimal_separator):?string - Parameter default value added for position #3 (
$decimal_separator):"." - Parameter type added for parameter #4 (
$thousands_separator):?string - Parameter default value added for position #4 (
$thousands_separator):","
number_format(
- $number,
+ float $num,
- $num_decimal_places,
+ int $decimals = 0,
- $dec_separator,
+ ?string $decimal_separator = ".",
- $thousands_separator
+ ?string $thousands_separator = ","
- )
+ ): string PHP 5.5
- Parameter name of parameter #3 changed:
$dec_seperatorto$dec_separator - Parameter name of parameter #4 changed:
$thousands_seperatorto$thousands_separator
number_format(
$number,
$num_decimal_places,
- $dec_seperator,
+ $dec_separator,
- $thousands_seperator
+ $thousands_separator
) number_format Function Availability
number_format Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |