计算机输出科学计数法,C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写啊?...
滿意答案
夢(mèng)塔LB
推薦于 2017.07.24
采納率:54%????等級(jí):9
已幫助:465人
sorry.由于沒(méi)有在計(jì)算機(jī)旁,沒(méi)有及時(shí)看到你的求助,你問(wèn):C語(yǔ)言里要對(duì)輸出的結(jié)果用科學(xué)計(jì)數(shù)法表示保留三位有效數(shù)字應(yīng)該怎么寫(xiě)?
我覺(jué)得應(yīng)該是
printf("%.3e",變量名);
而不是
printf("%3e",變量名);
==================
MSDN 中有關(guān)printf打印格式串:
%[flags] [width] [.precision] [{h | l | I64 | L}]type
的描述,其中對(duì)[.precision]是這么說(shuō)的:
The third optional field of the format specification is the precision specification.
(大義:格式規(guī)約中第三個(gè)選項(xiàng)段是關(guān)于小數(shù)的規(guī)則。)
==================
對(duì)于打印e, E類型的數(shù)據(jù)時(shí),[.precision]選項(xiàng)的作用是:
The precision specifies the number of digits to be printed after the decimal point. The last printed digit is rounded.
(大義:該精度指定了打印小數(shù)點(diǎn)后的位數(shù),之后的位數(shù)會(huì)被四舍五入)
Default precision is 6; if precision is 0 or the period (.) appears without a number following it, no decimal point is printed.
(大義:缺省情況下,該精度為6,如果精度值為0或者小數(shù)點(diǎn)后沒(méi)有緊跟著數(shù)字,則不會(huì)打印小數(shù)部分)
==================
例:
#include
int main()
{
float b = 100000.55555f;
printf("%3e\n",b);
printf("%.3e\n",b);
return 0;
}
輸出結(jié)果為:
1.000006e+005
1.000e+005
00分享舉報(bào)
總結(jié)
以上是生活随笔為你收集整理的计算机输出科学计数法,C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写啊?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux-zip和unzip命令
- 下一篇: 51单片机c语言秒表,51单片机秒表C程