%
starts a conversion specification.
.7
says to use a precision of seven digits after the decimal point.
l
says to use a “longer” type than the default. For floating-point, this means double
(which is longer than float
).
e
says to use exponential form: The number is converted to the style [-]d.ddde±dd. That is, a minus sign if appropriate followed by a number followed by “e” to indicate an exponent, and then a signed number to indicate a power of ten. For example, “3.45e-13” represents 3.45?10?13. The first number is always produced with one digit before the decimal point and as many digits after it as specified by the precision. So %.2e
converts 3.45, 34.5, and 345. to “3.45e+0”, “3.45e+1”, and “3.45e+2”.
Notes
The meaning of the precision differs depending on the conversion performed. For integer conversions, it is the minimum number of digits printed. For g
conversions, it is the number of significant digits.
For historic reasons, float
arguments to printf
are promoted to double
, so floating-point conversions with and without l
are the same: They expect a double
argument. This is different with scanf
, it takes a pointer to a float
or double
, and the l
is needed to distinguish them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…