Printf
1. Conversion specifiers
% A (% A) floating point number, hexadecimal number, and P-(p-) Notation (c99)
% C characters
% D signed decimal integer
% F floating point number (including float and doulbe)
% E (% E) floating point number index output [E-(e-) Note]
% G (% G) floating point number does not show meaningless zero "0"
% I signed decimal INTEGER (same as % d)
% U unsigned decimal integer
% O octal integer e.g. 0123
% X (% x) hexadecimal integer 0f (0f) e.g. 0x1234
% P pointer
% S string
% "%"
2. Flag
Left alignment: "-" e.g. "%-20 s"
Right alignment: "+" e.g. "% + 20 s"
Space: If the symbol is positive, space is displayed. If the symbol is negative, "-" e.g. "% 6.2f" is displayed"
#: PairClass C, S, D, and u have no effect. For Class O, prefix o is added for output; For Class X, prefix 0x is added for output;
The decimal point is given for Class E, G, and F when the result has decimal places.
3. Format String (Format)
[Flag] [minimum output width] [. Precision] [length] Type
"%-MD": Left alignment. If the M ratio is small, it is output as needed.
"% M. Ns": output M-bit. Take the string (from left) N-bit, left fill space, when n> m or M is omitted, M = N
E.g. "% 7.2 s" input China
Output "ch"
"% M. NF": Output floating point number. M indicates the width, and N indicates the right digit of the decimal point.
E.g. "% 3.1f" input 3852.99
3853.0 output
Length: H short integer, l long integer