The Number_format () function formats numbers by using thousands of groupings.
Grammar
Number_format (Number,decimals,decimalpoint,separator)
Parameters |
Description |
Number |
Necessary. The number to format. If no other parameters are set, the number is formatted with no decimal point and comma (,) as the delimiter. |
Decimals |
Optional. How many decimal places are specified. If this parameter is set, the number is formatted with a dot (.) as the decimal point. |
Decimalpoint |
Optional. Specifies a string to use as a decimal point. |
Separator |
Optional. Specifies the string to use as the thousand 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. |
Hints and notes
Note: The function supports one, two, or four parameters (not three).
Example
Copy CodeThe code is as follows:
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 are optional. But the third and fourth of the actual tests must both be present, either set or not set.
No third and fourth parameters are set:
Number_format (13526, 2); Echo 13,526.00;
If you add this number to the process, you will only get a 13!.
Set the third and fourth parameters
Number_format (23125, 2, '. ', '); Echo 23125.00;
Then the processing of the number after the operation will be executed correctly!
The third parameter of the function indicates what is represented by the ' decimal ' position, which can be defaulted. , can also be set to ', ' and other symbols. Ps: But I'm sure no one would do that.
The fourth one indicates what to use to divide the numbers every thousand. If there are no special requirements, it is best to set the operation to NULL.
http://www.bkjia.com/PHPjc/325416.html www.bkjia.com true http://www.bkjia.com/PHPjc/325416.html techarticle The Number_format () function formats numbers by using thousands of groupings. The syntax Number_format (number,decimals,decimalpoint,separator) parameter describes number required. The number to format. If ...