首页 > 解决方案 > 在 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

标签: c++mathdouble

解决方案


推荐阅读