判断浮点数是否为整数

Posted spzeno

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断浮点数是否为整数相关的知识,希望对你有一定的参考价值。

#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;

 

以上是关于判断浮点数是否为整数的主要内容,如果未能解决你的问题,请参考以下文章