Rounding a double to 5 decimal places in Java ME

前端 未结 8 471
旧时难觅i
旧时难觅i 2020-12-10 05:18

How do I round a double to 5 decimal places, without using DecimalFormat?

8条回答
  •  执念已碎
    2020-12-10 05:45

    public static double roundNumber(double num, int dec) {
            return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
    }
    

提交回复
热议问题