I doing a simple calculation from 2 variable and I got in to an issue... In fact when I try to do " double d = 1000 (which is the first var) / 3600 (which is the 2nd var); it result in a 0. So why ? Any hint about that ?
Asked
Active
Viewed 147 times
-4
-
21000 and 3600 are integers, not doubles. – chrylis -cautiouslyoptimistic- Oct 24 '18 at 15:40
-
1`1000` and `3600` are both int's, even though `d` is a `double`. Change it to `1000.0/3600.0` – GBlodgett Oct 24 '18 at 15:40
-
Thanks for you comments ^^ – ZeTioZ Oct 24 '18 at 15:47
-
double d = (double) 1000 / (double) 3600; // d = 0.2777777777777778 – Ilya Oct 24 '18 at 15:54
1 Answers
1
1000 and 3600 are ints, so when you do 1000 / 3600 you get 0. Then, you are assigning double d to this result of zero. You can instead write 1000.0/3600.0 or if these two numbers are variables, you can cast them to doubles first.

jsones
- 91
- 4
-
-
@ZeTioZ, you could do that ... but it is sufficient to convert only one number to a double and it will still work – mettleap Oct 24 '18 at 15:51
-
Thanks for your help ^^ I figured it out with your solution :) PS: How I make this question "resolved" ? – ZeTioZ Oct 24 '18 at 18:18