Rounding a double to 5 decimal places in Java ME

前端 未结 8 470
旧时难觅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:52

    DecimalFormat roundFormatter = new DecimalFormat("########0.00000");
    
    public Double round(Double d)
        {
            return Double.parseDouble(roundFormatter.format(d));
        }
    

提交回复
热议问题