Why can't I multiply a float?

Posted by Dpp on Stack Overflow See other posts from Stack Overflow or by Dpp
Published on 2010-06-13T05:00:25Z Indexed on 2010/06/13 5:02 UTC
Read the original article Hit count: 268

Filed under:
|

I was quite surprised why I tried to multiply a float in C (with GCC 3.2) and that it did not do as I expected.. As a sample:

int main() {
  float nb = 3.11f;
  nb *= 10;
  printf("%f\n", nb);
}

Displays: 31.099998

I am curious regarding the way floats are implemented and why it produces this unexpected behavior?

© Stack Overflow or respective owner

Related posts about c

    Related posts about float