Home >Backend Development >PHP Tutorial >Implementation code of php number_format() function to format numbers by thousands grouping_PHP Tutorial
Definition and Usage
The number_format() function formats a number by grouping by thousands.
Syntax
number_format(number,decimals,decimalpoint,separator)
Parameter Description
number Required. The number to format. If no other parameters are set, numbers are formatted without a decimal point and with commas (,) as delimiters.
decimals are optional. Specify the number of decimals. If this parameter is set, numbers are formatted using a period (.) as the decimal point.
decimalpoint is optional. Specifies the string used as the decimal point.
separator Optional. Specifies the string used as thousands separator. Only the first character of the parameter is used. For example, "xyz" only outputs "x".
Note: If this parameter is set, all other parameters are required.
Tips and Notes
Note: This function supports one, two or four arguments (not three).
Example: