SoFunction
Updated on 2025-03-09

The implementation code of the php number_format function formats numbers through thousands of groupings

Definition and usage
The number_format() function formats numbers by grouping thousands of digits.

grammar
number_format(number,decimals,decimalpoint,separator)

Parameter description
number Required. The number to format. If no other parameters are set, the number is formatted without a decimal point and is a comma (,) as the separator.

Decimals are optional.Specify how many decimals. If this parameter is set, the number (.) is used as the decimal point to format the number.

decimalpoint optional. Specifies a string used as a decimal point.

separator optional.Specifies a string used as a thousand separator. Use only the first character of this parameter. For example, "xyz" only outputs "x".
Note: If this parameter is set, all other parameters are required.

Tips and comments
Note: This function supports one, two, or four parameters (not three).

example:

Copy the codeThe code is as follows:

<?php
echo number_format("1000000");
echo number_format("1000000",2);
echo number_format("1000000",2,",",".");
?>

Output:
Copy the codeThe code is as follows:

1,000,000
1,000,000.00
1.000.000,00