The number_format () function uses a thousand-bit grouping to format numbers.
Syntax
Number_format (number, decimals, decimalpoint, separator)
| Parameters |
Description |
| Number |
Required. The number to be formatted.
If no other parameter is set, the number is formatted as a comma (,) without a decimal point. |
| Decimals |
Optional. Specifies the number of decimal places. If this parameter is set, the period (.) is used as the decimal point to format the number. |
| Decimalpoint |
Optional. Specifies the string used as the decimal point. |
| Separator |
Optional. A string that is required to be used as a thousands 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 codeThe Code is as follows:
<? Php
Echo number_format ("1000000 ");
Echo number_format ("1000000", 2 );
Echo number_format ("1000000", 2 ,",",".");
?>
Output:
1,000,000
1,000,000.00
1.000.000, 00
Interesting number_format
Number_format (number, decimals, decimalpoint, separator)
There are four parameters,
The first and second parameters are required, and the third and fourth parameters are optional. However, in actual tests, the third and fourth parameters must both exist, that is, either set or not set.
The third and fourth parameters are not set:
Number_format (13526, 2); echo 13,526.00;
If you accumulate the processed number, only 13 is returned !.
Set the third and fourth parameters.
Number_format (23125, 2, '.', ''); echo 23125.00;
Then, if you perform an operation on the processed number, it will be executed correctly!
The third parameter of this function indicates the position of the 'decimal point '. It can be set to', 'or other symbols by default. Ps: but I believe no one will do this.
The fourth parameter indicates what is used to separate numbers every thousands of digits. If there are no special requirements, it is best to set it to null if you want to perform computation again.