1

我有

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

我想确保它以小数点后三位返回。我试过了

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 回答