format when printing

http://msdn.microsoft.com/en-us/library/vstudio/56e442dc.aspx

%[flags] [width] [.precision] [{h | l | ll | w | I | I32 | I64}] type

width

Optional decimal number that specifies the minimum number of characters that are output. 

If the number of characters in the output value is less than the specified width,

blanks are added to the left or the right of the values—depending on whether the left alignment flag (-) is specified—until the minimum width is reached.

precision

Optional decimal number that specifies the maximum number of characters that are printed for strings, the number of significant digits or the number of digits after the decimal-point character for floating-point values, or the minimum number of digits that are printed for integer values. 

float:  printf( "%.*f", 3, 3.14159265 ); /* 3.142 output */

string: The precision specifies the maximum number of characters to be printed. Characters in excess of precision are not printed.

原文地址:https://www.cnblogs.com/aprilapril/p/3465294.html