我正在尝试运行以下程序并且它可以工作,但是当我输入一个超过 6 位小数的值时,它会不断被舍入/截断,例如 2.999999 --> 3。如何设置它以使其停止这样做?
int main()
{
double n=0, x=0;
while (cin >> n >> x) //will keep going until an integer is not entered
{
cout << "You entered the two integers " << x << " and " << n << endl;
if (x-n <= (1.0/10000000) && n-x <= (1.0/10000000))
cout << "The numbers are almost equal" << endl;
}
return 0;
}