floats are not always 100% accurate, they can't be because of the way that they're stored. If you say float a = 0.8, a could really be 0.800000000001 or something like that. To compensate for this, you should use some sort of threshold. try if (fabs(a-0.8) < 1.0e-5) instead