Php format the number. when the number of digits is insufficient, add 0 to complement it. This article provides two implementation methods, sprintf and number_format, respectively. If you need it, come and have a look. Example of formatting a number in php.
1. string sprintf () function syntax Sprintf (format, arg1, arg2, arg ++)
Parameters |
Description |
Format |
Required. Conversion format. |
Arg1 |
Required. Specifies the parameter inserted at the first % symbol in the format string. |
Arg2 |
Optional. Specifies the parameter inserted at the second % symbol in the format string. |
Arg ++ |
Optional. Specifies the parameters inserted to the third, fourth, and other % symbols in the format string. |
DescriptionThe format parameter is the conversion format. it starts with the percent sign ("%") and ends with the conversion character. The following possible format values: %-return percent sign % B-binary number % c-following the ASCII value character % d-signed decimal number % e-resumable notation (such as 1.5e + 3) % u-unsigned decimal number % f-floating point number (local settings aware) % F-floating point number (not local settings aware) % o-octal digits % s-string % x-hexadecimal digits (lowercase letters) % X-hexadecimal digits (uppercase letters) Parameters such as arg1, arg2, ++ are inserted to the percent sign (%) in the main string. This function is executed step by step. In the first % symbol, insert arg1, at the second % symbol, insert arg2, and so on. Example:
II. example of the format numeric function number_format:
|