0

So I have a bunch of calculations and I test for the results with some log statements.

Log.i(tag, "modulus is  " + modulusCalc);
Log.i(tag, "placevalue is  " + placevalue(modulusCalc));
Log.i(tag, "calulation is  " + (float)(494/1000));

Logcat shows:

  • modulus is 494
  • placevalue is 1000
  • calulation is 0.0

What's going on with the calculation?? I had the names of the values but I kept getting 0.0 so I tried to hard code the equation and I still get 0.0 but the answer should be 0.494.

I have an identifier that is supposed to hold the calculation (called "minutes") and I declared it as a float(float minutes;). I also tested with removing the float cast in the log for calculation.

Anyone have a clue what is happening? I've got no more ideas. My calculator gives me the correct results. It's not the division symbol, because right before that calculation I divide 2 values together and I get the right results.

Anon
  • 137
  • 2
  • 16
  • 1
    `(float) 494 / 1000`, you messed the parentheses up and are doing an integer division instead, which correctly gives zero. Although to be exact, you're right, Android Studio is not calculating the value, Android Studio is just an IDE. – Nicolas Oct 12 '20 at 23:52
  • 1
    Also read this: [Why does the division of two integers return 0.0 in Java?](https://stackoverflow.com/questions/4931892/why-does-the-division-of-two-integers-return-0-0-in-java) – Nicolas Oct 12 '20 at 23:53
  • Thanks Nicolas lol. Nearing an hour on this but I knew I was missing something stupid. I did try searching for similar answers, but I phrased it differently (writing android studios and not java). – Anon Oct 12 '20 at 23:56

0 Answers0