问题描述:

This question already has an answer here:

  • How to round a number to n decimal places in Java

    26 answers

网友答案:

If you need to format the output, for example to print it or display it in a textview, use:

DecimalFormat threeDecRound = new DecimalFormat();
threeDecRound.setMaximumFractionDigits(3);
threeDecRound.setRoundingMode(RoundingMode.HALF_DOWN);
threeDecRound.format(number)
相关阅读:
Top