当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to round to 3 decimals?

问题描述:

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)
分享给朋友:
您可能感兴趣的文章:
随机阅读: