5

How does one solve the "integer division in floating-point context" warning, in this line of code:

int fps = 60;
double timePerTick = 1000000000 / fps;
Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

8

When dividing two ints, you'll be using integer division, and only then promoting the result to a double, losing all the precision after the decimal point. You can use floating point precision by using a double literal instead:

double timePerTick = 1000000000.0 / fps;
// Here -----------------------^
Mureinik
  • 297,002
  • 52
  • 306
  • 350