【发布时间】:2018-02-14 05:21:59
【问题描述】:
DecimalFormat newFormat = new DecimalFormat("##.##"); 给我以下值的意外结果:
for value 0.005 = 0.00
0.015 = 0.02
DecimalFormat 未格式化 0.005 to 0.01。当提供DecimalFormat newFormat = new DecimalFormat("##.##"); 时,请告诉我如何获取0.005 to 0.01 的值。
提前致谢。
【问题讨论】:
-
使用 Match.round(val) 然后应用 DecimalFormat
-
添加你目前尝试过的代码。
-
双 d= 0.005; DecimalFormat newFormat = new DecimalFormat("#.##"); double twoDecimal = Double.parseDouble(newFormat.format(d)); System.out.println(twoDecimal);