计算机输出科学计数法,C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写啊?...
滿意答案
夢塔LB
推薦于 2017.07.24
采納率:54%????等級:9
已幫助:465人
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
00分享舉報
總結
以上是生活随笔為你收集整理的计算机输出科学计数法,C语言里要对输出的结果用科学计数法表示保留三位有效数字应该怎么写啊?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux-zip和unzip命令
- 下一篇: 51单片机c语言秒表,51单片机秒表C程