判断浮点数是否为整数

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-2;
bool f(double x)
{
    if(x>(int)(x+0.5))
    {
         if(x-(int)(x+0.5)<eps)
            return true;
    }
    else
    {
        if((int)(x+0.5)-x<eps)
            return true;
    }

    return false;
}
int main()
{
    cout<<f(1.000000000002)<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/spzeno/p/11297312.html