【发布时间】:2013-07-23 03:05:01
【问题描述】:
我有
double a= = 13;
double b = 6;
double c = a/b;
我想确保它以小数点后三位返回。我试过了
Math.round(c); //gives me an error instead.
【问题讨论】:
-
显示什么错误?
标签: android math rounding decimal
我有
double a= = 13;
double b = 6;
double c = a/b;
我想确保它以小数点后三位返回。我试过了
Math.round(c); //gives me an error instead.
【问题讨论】:
标签: android math rounding decimal
如果您需要格式化输出,例如打印或在文本视图中显示,请使用:
DecimalFormat threeDecRound = new DecimalFormat();
threeDecRound.setMaximumFractionDigits(3);
threeDecRound.setRoundingMode(RoundingMode.HALF_DOWN);
threeDecRound.format(number)
【讨论】: