It is important to understand the flow of execution in a line of code. You are right to assume that setting the right side of the equation equal to double (on the left side) will implicitly convert the solution into a double. However, thread execution describes that x / y is evaluated on its own before you even get to the double pct = code. Thus, since the two int are divisible by each other, they will evaluate the int solution (in this case, rounding to zero) before they are implicitly converted to double.
As already noted, you need to specify int variables as double , so that the solution turns out to be double , and not as int .
Ben mccormack
source share