-3

I have used

Class CheckFloat {  
    float floatVal;  
    public boolean isFloatZero(){  
        return floatVal==0.0f;  
    }
}

Is there a better way of doing it?

Filburt
  • 17,626
  • 12
  • 64
  • 115
PipoTells
  • 511
  • 6
  • 11
  • 4
    Yes. `if(myFloat == 0)`. Simple, understood by all, no need for an additional class and a method...it's got everything you need. – Kayaman Nov 23 '17 at 07:25
  • @Kayaman [What's wrong with using == to compare floats in Java?](https://stackoverflow.com/questions/1088216/whats-wrong-with-using-to-compare-floats-in-java) – lexicore Nov 23 '17 at 07:29
  • 2
    @lexicore checking if a float is 0 is well defined. No need for epsilon here. – Kayaman Nov 23 '17 at 07:30

2 Answers2

0

You can use Math.signum(x) == 0. It should never fail.

-2

easily by some checking you can do it First if(floatVal==0) sop("it is zero") Second float b=floatVal; if(b/floatVal!=1) sop("it is zero"); But you should be also aware about the divide by zero error here.