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

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

梦塔LB

推荐于 2017.07.24

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率: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分享举报

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值