Many times we need to format the numbers, such as the number of bits in front plus 0 complement. PHP can be easily implemented, because PHP comes with functions related to functions.
sprintf () function
1. Syntax
sprintf (format,arg1,arg2,arg++)
Parameters |
Description |
Format |
Necessary. Conversion format. |
Arg1 |
Necessary. Specifies the parameter that is inserted into the first% symbol in the format string. |
Arg2 |
Optional. Specifies the parameter that is inserted into the second% symbol in the format string. |
arg++ |
Optional. Specifies the parameter that is inserted into the format string third to fourth, and so on, in the% symbol. |
2. Description
The parameters format is the converted format, starting with the percent sign ("%") to the end of the converted character. The following possible format values are:
- Percent-return percentage symbol
- %b-Binary number
- %c-Characters in accordance with ASCII values
- %d-Signed decimal number
- %e-Sustainable counting method (e.g. 1.5e+3)
- %u-Unsigned decimal number
- %f-Floating point (Local settings Aware)
- %F-Floating point number (not local settings aware)
- %o-Eight binary number
- %s-String
- %x-16 binary number (lowercase letters)
- %x-16 decimal digits (uppercase letters)
Arg1, arg2, + + etc parameters will be inserted into the main string percent percent (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on.
3. Format number Number_format ()
http://www.bkjia.com/PHPjc/752554.html www.bkjia.com true http://www.bkjia.com/PHPjc/752554.html techarticle many times we need to format the numbers, such as the number of bits in front plus 0 complement. PHP can be easily implemented, because PHP comes with functions related to the function. PHP//Generate 4 digits, ...