在 cout 中显示数字小数格式而不是指数

发布于 2024-11-07 11:44:34 字数 180 浏览 0 评论 0原文

我计算了浮点数总数,得到了一个类似 509990e-405 的数字。我假设这是简短的版本;我如何cout将此作为完整数字?

   cout << NASATotal << endl;

就是我现在拥有的。

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;

is what I have now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还不是爱你 2024-11-14 11:44:34

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

#include <iomanip>

// ...

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

输出:

0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000050999000000

If you really want this is another question.

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;

Output:

0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050999000000

If you really want this is another question.

无边思念无边月 2024-11-14 11:44:34

您可以编写自己的 BigNumber 类,将结果存储为字符串。您必须实现所有数字运算,我猜性能将是一个问题。但这是可以做到的,没问题——假设这就是你想要的。

You can write your own BigNumber class that stores the results as strings. You would have to implement all of your numeric operations and I'm guessing performance will be an issue. But it can be done, no problem -- assuming that is what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文