c++ - 在 C++ 中打印大数字
问题描述
在c ++中获取以下代码
#include <iostream>
#include <math.h>
using namespace std;
int main(){
double one, out;
one = (pow(10, 10) - 1 ) / 9; //1111111111
out = one * pow(10, 12) + one * 80 + 9;
cout << fixed << out << endl;
}
它返回
1111111111088888872960.000000
变量out
应该等于1111111111088888888889
。
当我在https://www.wolframalpha.com
中粘贴以下公式时,等于变量结果是正确的。你能告诉我我哪里做错了吗?one
(10^10 - 1)/9 * 10^12 + 80 * (10^10 - 1)/9 + 9
解决方案
推荐阅读
- javascript - 无法使用 Google App 脚本循环到 Google 电子表格中的列末尾
- shell - 无法使用 nohup 命令运行 Shell 脚本
- audio - 哪个工具可以根据字幕时间戳将音频文件切割成更小的持续时间段?
- c# - 面板覆盖未绘制在标签上
- javascript - 取回用户填写的信息以供第二次使用(使用 cookie)
- laravel - laravel 查看组件
- reactjs - 错误:“重新渲染过多。React 限制渲染次数以防止无限循环”
- c - 单链表实现的函数调用问题
- substrate - Parity Substrate 教程中的依赖关系中断
- python - Mypy-仅针对指定文件生成报告