Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

c++ - What does "%.7le " in printf means?

What does

fprintf(fp, "%.7le ", data);

means?

I don't know what "%.7le " is mean.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

% 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.ddddd. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...