0.1 is a literal double .
Since 0.1 cannot be represented exactly in floating point, a float set to 0.1 compares false with a double parameter of 0.1.
Your comparison will behave as intended if you use the literal float : 0.1f (note the suffix f : should not be confused with your variable name):
float foo = 0.1; if (foo == 0.1f){
source share