Definitions and usage
The Number_format () function formats a number by a thousands group.
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 with no decimal point and comma (,) as the separator.
Decimals Optional. specify how many decimal places. If this argument is set, the number (.) is used as the decimal point to format the digits.
decimalpoint Optional. A string that is used as a decimal point.
Separator Optional. A string that is used as a thousand separator. Use only the first character of the parameter. For example, "XYZ" outputs only "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 Code code as follows:
<?php
Echo Number_format ("1000000");
Echo Number_format ("1000000", 2);
Echo Number_format ("1000000", 2, ",", ".");
?>
Output:
Copy Code code as follows:
1,000,000
1,000,000.00
1.000.000,00