Java 开始四舍五入为双倍

Java 开始四舍五入为双倍,java,Java,如何用1.5取整,但我知道我们可以用1.6取整。请给出您的指导。 我想得到双精度值,而不需要像这样对其小数进行四舍五入。 我无法使用1.5的roundingmode double d1 = 1234567812342134.45678567; DecimalFormat df = new DecimalFormat(".00000"); df.setMaximumFractionDigits(5); //df.setRoundingMode(RoundingMode.DO

如何用1.5取整,但我知道我们可以用1.6取整。请给出您的指导。 我想得到双精度值,而不需要像这样对其小数进行四舍五入。 我无法使用1.5的roundingmode

   double d1 = 1234567812342134.45678567;
   DecimalFormat df = new DecimalFormat(".00000");
   df.setMaximumFractionDigits(5);
   //df.setRoundingMode(RoundingMode.DOWN); 
   System.out.println(df.format(d1));
预期输出: 1234567812342134.45678

现在输出:
1234567812342134.50000

问题在于你的
双d1=1234567812342134.45678567


它太大了,
double
无法存储到那样的准确度,如果从任意一端删除5位数字,则将得到所需的舍入值;您的
DecimalFormat
相关代码在其他方面都很好。

根本不清楚您想要实现什么。请提供更多信息。更新问题请检查。