我在Java中舍入问题(即整体= 1387.583515625输出是x = 5836而不是5835.我已经搜索过这个问题,我已经尝试了各种答案,但我仍然可以“不像是会得到它哟工作。任何想法?在Java中舍入错误
DecimalFormat df = new DecimalFormat(".####");
df.setRoundingMode(RoundingMode.CEILING);
int x = Integer.parseInt(String.format(df.format(whole)).split("\\.")[1]);
如果您要求必须将它舍入,为什么输出是5835? – Ferrybig
由RoundingMode.FLOOR替换RoundingMode.CEILING –
oooooooh ....谢谢。我现在感到很蠢。 –