Solve Integer Division in Floating Point Context

Solve Integer Division in Floating Point Context

When doing:

double a = 1000000000 / FPS;

It gives me the warning:

Integer division in floating point context.

How can I solve this?

1

4 Answers

You have two options. Add .0 at the end as such:

double a = 1000000000.0 / FPS;

or adding d at the end.

double a = 1000000000d / FPS;
4

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.

3

Suppose if you are using a variable like this -

int totalPresentStudentCount,count;
(totalPresentStudentCount/count) * 100.00

Then simply add 1.0 with any of the doubles like that -

int totalPresentStudentCount,count;
(totalPresentStudentCount*1.0/count) * 100.00

double a = 1000000000.00 / FPS; It is true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.