你能解释一下为什么吗
printf("%2.2e", 1201.0);
给出结果 1.20e+03
而不仅仅是 12.01e2
?
我的想法:默认数字是 1201.0,说明符告诉数字后面应该有 2 个数字。
怎么了?
最佳答案
根据 Wikipedia :
In normalized scientific notation, the exponent b is chosen so that the absolute value of a remains at least one but less than ten (1 ≤ |a| < 10). Thus 350 is written as 3.5×102. This form allows easy comparison of numbers, as the exponent b gives the number's order of magnitude. In normalized notation, the exponent b is negative for a number with absolute value between 0 and 1 (e.g. 0.5 is written as 5×10−1). The 10 and exponent are often omitted when the exponent is 0.
Normalized scientific form is the typical form of expression of large numbers in many fields, unless an unnormalised form, such as engineering notation, is desired. Normalized scientific notation is often called exponential notation—although the latter term is more general and also applies when a is not restricted to the range 1 to 10 (as in engineering notation for instance) and to bases other than 10 (as in 3.15× 220).
关于c - printf() 中的 e 格式和精度修饰符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29520231/