c - printf() 中的 e 格式和精度修饰符

标签 c printf format-specifiers

你能解释一下为什么吗

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/

相关文章:

c++ - 使用 VideoCapture 读取目录中的图像不起作用

C 程序返回 0 而不是整数输入序列中最大出现的整数

c - 为什么我们应该在 scanf ("% [^\n]")中放置空格?

c - 在 scanf 中使用 [^ 符号的目的是什么?

c - 我收到错误 "warning: assignment to ' char' from 'char *' made integer frompointer without a Cast”

c++ - 判断当前字体是否支持 unicode 字符的简便方法?

c - 为什么ebx保存在调用gets的简单函数的栈帧中?

c - printf 是否需要 %zu 说明符?

c - printf 和 scanf 的逻辑问题

c - 格式说明符内的格式说明符可更改前导零的大小