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

dongyan
  • 93
  • 1
  • 4

2 Answers2

16

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))
}
babbageclunk
  • 8,523
  • 1
  • 33
  • 37
10

You could achieve it by doing a modulus

func isFloatInt(floatValue float64) bool {
    return math.Mod(floatValue, 1.0) == 0
}
Dovydas Bartkevičius
  • 1,721
  • 13
  • 19