0

I have a double value and I need to divide it with an integer value. I need the result to be an integer value again. Then I need to perform modulo division on the double value to get the reminder. I got the following code:

double num = in.nextDouble();

int div = num/20.0;
int modulo = num%20.0;

System.out.println("div= "+div);
System.out.println("modulo= "+modulo);

error: possible loss of precision
int div = num/20.0; 

error: possible loss of precision
int modulo = num%20.0;
  • 1
    So what is the problem with the current code? Is there an error? Wrong output? What were you expecting to see? (In truth, you have a compilation error because `div` and `modulo` are `int`s and the result of the calculation is `double` so you need to convert the `double` to `int`, but please include such information for future questions). – Tunaki Jun 27 '16 at 20:08
  • @Tunaki I don't think this question is a duplicate of the one you indicated. I get why you picked it - it's the solution to the problem you ID'd in your comment - but this question isn't actually a duplicate of that question. – dcsohl Jun 27 '16 at 20:20
  • @dcsohl I don't see a real question asked. As per the title, the issue seems to be getting an integer result of the calculation (that is why I chose this duplicate) but I will be happy to reopen if the question is clarified with a clear problem statement. – Tunaki Jun 27 '16 at 20:32

0 Answers0