percent-Returns
%b– return binary number
%c– returns the character corresponding to the ASCII value
%d– decimal number with plus sign
%e– Scientific counting symbols (e.g.: 1.2e+2)
%u– the unsigned decimal number.%ul Long integer without symbol
%f– Floating-point data (local setting)
%f– Floating-point data (non-local settings)
%o– octal number
%s– String
%x– hexadecimal number (lowercase letters) for example: sprintf (S, "% #010x", 128);//Generate "0x00000080"
%x– hexadecimal number (capital letter)
If the% is followed by numbers, such as:%2f,%2.3f these,%M.N and so on, the M in front of the decimal point represents the number of digits of the entire number,
n indicates how many bits are in the decimal point:
Double A = 326.3845;printf ("%10.3f\n", a);
The result is:
326.385 (Note that there is a space in front)
This shows that the rounding method is taken here.
If there are characters in front of M, then the spaces preceding the above results are complete with that character:
printf ("%04d", 3);
The result is:
0003
C++/C string Formatting