在 cout 中显示数字小数格式而不是指数
我计算了浮点数总数,得到了一个类似 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以强制输出不采用科学计数法,并具有足够的精度来显示您的小数字。
输出:
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.
Output:
If you really want this is another question.
您可以编写自己的 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.