Possible Duplicate:
Why does the division of two integers return 0.0 in Java?
I have some very confusing problem..
I want to calculate some stuff and after some debugging I saw that java calculates this arithmetic: 2 / 4 = 0.0 But it should be 0.5
2 & 4 are stored in integer variables
the result is stored in a double-type.
Did I miss something clearly?
It is because of integer division (Integer division rounds toward 0). Cast one of the operand to double type.
Example:
double temp = (double)2/4will give you correct results.