Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solve Integer division in floating point context [duplicate]

Tags:

java

double

When doing:

double a = 1000000000 / FPS;

It gives me the warning:

Integer division in floating point context.

How can I solve this?

like image 300
Dumm Coding Avatar asked Nov 27 '25 12:11

Dumm Coding


1 Answers

The warning occurs because you divide two integers 1000000000 and FPS, and the variable you want to assign the result to is double, a floating point type.

What you want instead is having a floating point division.
For this, one of the operands of the division has to be a floating point type.

You can do it in the following ways:

1000000000.0 / FPS; // make operand a floating point type (double)
1000000000.0f / FPS; //(float)
1000000000d / FPS; //(double)
(double)1000000000 / FPS; // cast operand to a floating point type (may be necessary if your operand is a variable)

and of course you can make FPS just a floating point variable instead of a integer variable.

like image 124
Raildex Avatar answered Nov 29 '25 02:11

Raildex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!