-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Windows and Java 8
A DESCRIPTION OF THE PROBLEM :
The value for 0.2 raised to power 3 is expected to be 0.008 however java function Math.pow results in 0.008000000000000002
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public class JavaMathPower {
public static void main(String args []){
double base = 0.2;
double exponent = 3;
double calVal = Math.pow(base,exponent);
System.out.println(calVal);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
0.008
ACTUAL -
0.008000000000000002
---------- BEGIN SOURCE ----------
public class JavaMathPower {
public static void main(String args []){
double base = 0.2;
double exponent = 3;
double calVal = Math.pow(base,exponent);
System.out.println(calVal);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use BigDecimal instead of double
Windows and Java 8
A DESCRIPTION OF THE PROBLEM :
The value for 0.2 raised to power 3 is expected to be 0.008 however java function Math.pow results in 0.008000000000000002
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public class JavaMathPower {
public static void main(String args []){
double base = 0.2;
double exponent = 3;
double calVal = Math.pow(base,exponent);
System.out.println(calVal);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
0.008
ACTUAL -
0.008000000000000002
---------- BEGIN SOURCE ----------
public class JavaMathPower {
public static void main(String args []){
double base = 0.2;
double exponent = 3;
double calVal = Math.pow(base,exponent);
System.out.println(calVal);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use BigDecimal instead of double
- duplicates
-
JDK-8279199 Modulo operations with floating point numbers are not always correct
-
- Closed
-