Floating point comparison

Viewed 15648
int main()
{
    float a = 0.7;
    float b = 0.5;
    if (a < 0.7)
    {
       if (b < 0.5) printf("2 are right");
       else         printf("1 is right");
    }
    else printf("0 are right");
}

I would have expected the output of this code to be 0 are right. But to my dismay the output is 1 is right why?

5 Answers
Related