C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写啊?

2022-08-10 教育 82阅读
sorry.由于没有在计算机旁,没有及时看到你的求助,你问:C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写?
我觉得应该是
printf("%.3e",变量名);
而不是
printf("%3e",变量名);
==================
MSDN 中有关printf打印格式串:
%[flags] [width] [.precision] [{h | l | I64 | L}]type
的描述,其中对[.precision]是这么说的:
The third optional field of the format specification is the precision specification.
(大义:格式规约中第三个选项段是关于小数的规则。)
==================
对于打印e, E类型的数据时,[.precision]选项的作用是:
The precision specifies the number of digits to be printed after the decimal point. The last printed digit is rounded.
(大义:该精度指定了打印小数点后的位数,之后的位数会被四舍五入)
Default precision is 6; if precision is 0 or the period (.) appears without a number following it, no decimal point is printed.
(大义:缺省情况下,该精度为6,如果精度值为0或者小数点后没有紧跟着数字,则不会打印小数部分)
==================
例:
#include
int main()
{
float b = 100000.55555f;
printf("%3e\n",b);
printf("%.3e\n",b);
return 0;
}
输出结果为:
1.000006e+005
1.000e+005
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com