方法我有下面的代碼段:得到錯誤輸出,同時使用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語句之前使用 –