1

私は持っている

double a= = 13;
double b = 6;
double c = a/b;

小数点以下3桁で返されることを確認したい。私は試した

Math.round(c); //gives me an error instead.
4

1 に答える 1

1

出力をフォーマットする必要がある場合 (たとえば、出力を印刷したり、テキストビューで表示したりする場合)、次を使用します。

DecimalFormat threeDecRound = new DecimalFormat();
threeDecRound.setMaximumFractionDigits(3);
threeDecRound.setRoundingMode(RoundingMode.HALF_DOWN);
threeDecRound.format(number)
于 2013-07-23T03:10:39.333 に答える