方法我有下面的代码段:得到错误输出,同时使用numberFormat.parse(“”)在Java
我传递值“55.00000000000000”并获得输出作为55.00000000000001。
但是,当我通过“45.00000000000000”和“65.00000000000000”我得到输出为45.0和65.0。
有人可以帮助我得到正确的输出为55.0。
NumberFormat numberFormat = NumberFormat.getPercentInstance(Locale.US);
if (numberFormat instanceof DecimalFormat) {
DecimalFormat df = (DecimalFormat) numberFormat;
df.setNegativePrefix("(");
df.setNegativeSuffix("%)");
}
Number numericValue = numberFormat.parse("55.00000000000000%");
numericValue = new Double(numericValue.doubleValue() * 100);
System.out.println(numericValue);
谢谢但System.out.println(numericValue);我在核心Java工作区中使用,但在实际代码中没有System.out.println语句。如何在println语句之前使用 –