《C++ Primer》第五版,中文版。p33。
1.999999999999999(比转换之后少是 2 的少个 9) 也是 1。
微软免费 IDE 2015。g++ 好像也一样。
#include
using namespace std;
int main()
{
double d = 1.9999999999999999;
int i = d;
cout << i << endl;
return 0;
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为这个
你运行一下,看看输出什么。
因为浮点数并不是能精确表示所有的数,有些数只能是保存的近似值。这里的
1.9999999999999999,就会保存其近似值2。