Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有
double a= = 13; double b = 6; double c = a/b;
我想确保它以小数点后三位返回。我试过了
Math.round(c); //gives me an error instead.
如果您需要格式化输出,例如打印或在文本视图中显示,请使用:
DecimalFormat threeDecRound = new DecimalFormat(); threeDecRound.setMaximumFractionDigits(3); threeDecRound.setRoundingMode(RoundingMode.HALF_DOWN); threeDecRound.format(number)