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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…