Converting the output is too late; the calculation has already taken place in integer arithmetic. You need to convert the inputs to double
:
System.out.println((double)completed/(double)total);
Note that you don't actually need to convert both of the inputs. So long as one of them is double
, the other will be implicitly converted. But I prefer to do both, for symmetry.