查看format的帮助或者手册
可以看到例子和解释
下面就是帮助文件里面的解释和举例
The %f format
In %w.df, w is the total output width, including sign and decimal point,
and d is the number of digits to appear to the right of the decimal
point. The result is right-justified.
The number 5.139 in %12.2f format displays as
----+----1--
5.14
When d==0, the decimal point is not displayed. The number 5.14 in
%12.0f format displays as
----+----1--
5
%-w.df works the same way, except that the output is left-justified in
the field. The number 5.139 in %-12.2f displays as
----+----1--
5.14
The %g format
In %w.dg, w is the overall width, and d is usually specified as 0, which
leaves up to the format the number of digits to be displayed to the
right of the decimal point. If d!=0 is specified, then not more than d
digits will be displayed. As with %f, a minus sign may be inserted to
left-justify results.
%g differs from %f in that (1) it decides how many digits to display to
the right of the decimal point, and (2) it will switch to a %e format if
the number is too large or too small.
The number 5.139 in %12.0g format displays as
----+----1--
5.139
The number 5231371222.139 in %12.0g format displays as
----+----1--
5231371222
The number 52313712223.139 displays as
----+----1--
5.23137e+10
The number 0.0000029394 displays as
----+----1--
2.93940e-06
The %e format
%w.de displays numeric values in exponential format. w records the
width of the format. d records the number of digits to be shown after
the decimal place. w should be greater than or equal to d+7 or, if
3-digit exponents are expected, d+8.
The number 5.139 in %12.4e format is
----+----1--
5.1390e+00
The number 5.139*10^220 is
----+----1--
5.1390e+220
|