Search code examples
go

How to check if float value is actually int


func isFloatInt(floatValue float64) bool{
//What's the implementation here?

}

Test cases:
input: 1.5 output: false;
input: 1 output: true;
input:1.0 output: true;


Solution

  • I just checked on the playground, this does the right thing with NaN as well.

    func isIntegral(val float64) bool {
        return val == float64(int(val))
    }