1

Why?

11979999 / 10000 = 1197.999877930

With

printf("%f\n", static_cast<double>(((float)11979999 / (float)10000)));

Instead of

1197.9999

And how to fix it?

PeeS
  • 1,164
  • 3
  • 20
  • 43
  • 1
    Possible duplicate of [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Dan Lowe Oct 30 '15 at 00:09

1 Answers1

3

In your code you did the calculation in single precision, then you converted the result to double. If you want double precision, do the calculation in double precision:

  printf("%f\n", (double)11979999 / (double)10000);
A.S.H
  • 29,101
  • 5
  • 23
  • 50