#include <iostream>
using namespace std;
int main()
{
cout.precision(32);
float val = 268433072;
float add = 13.5;
cout << "result =" << (val + add) << endl;
}
我正在用标准编译上述程序g++ main.cc
并运行它./a.out
然而,我收到的输出是,
result =268433088
显然,这不是正确的答案。为什么会这样?
编辑double
:使用代替时不会发生这种情况float