0
は小数点以下の桁数にかかわらず ".0"で終わる数字として表示されます。 massCounter[]
のインデックスは2倍です。全体の数ではなく、最初の小数点以下をどのように丸めるのですか?配列で丸めて
public static double massTotal(double[] massCounter) {
double massTotal = 0.0;
for (int i = 0; i < massCounter.length; i++) {
massTotal += Math.round(massCounter[i] * 10.0/10.0);
}
return massTotal;
}
ありがとうございます!
:https://stackoverflow.com/questions/ 153724/n-to-n-decimal-places-in-java?rq = 1、特にDecimalFormat – reden
'* 10.0/10.0'のポイントは何ですか? – shmosel
あなたは 'Math.round(massCounter [i] * 10.0)/ 10.0'を行うことを意味すると思います。 – shmosel