在cout中将数字显示为十进制格式而不是指数 [英] Display a number decimal format instead as an exponential in cout

查看:85
本文介绍了在cout中将数字显示为十进制格式而不是指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算了总的浮点数,并得到了一个类似 509990e-405 的数字.我假设这是一个简短的版本;我怎么能 cout 作为一个完整的数字?

I calculated a total of floats and I got a number like 509990e-405. I'm assuming this is the short version; how can I cout this as a full number?

   cout << NASATotal << endl;

这就是我现在拥有的.

推荐答案

您可以强制输出不采用科学计数法,并且要具有足够的精度以显示您的小数字.

You can force the output to be not in scientific notation, and to have the sufficient precision to show your small number.

#include <iomanip>

// ...

long double d = 509990e-405L;
std::cout << std::fixed << std::setprecision(410) << d << std::endl;

输出:

0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050999000000

如果您真的想要,这是另一个问题.

If you really want this is another question.

这篇关于在cout中将数字显示为十进制格式而不是指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆