我在Java中遇到舍入问题(即,整体= 1387.583515625,输出是x = 5836而不是5835。我之前搜索过这个问题,并且尝试了各种答案,但我似乎仍然无法开始工作吧。有什么想法吗?
DecimalFormat df = new DecimalFormat(".####");
df.setRoundingMode(RoundingMode.CEILING);
int x = Integer.parseInt(String.format(df.format(whole)).split("\\.")[1]);
最佳答案
查看此表来决定您想要什么 https://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html
df.setRoundingMode(RoundingMode.HALF_UP);
关于java - Java 中的舍入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35271305/