A DESCRIPTION OF THE PROBLEM :
double says 1.0 = 1.0
but Double says 1.0 does not equal 1.0
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
double test1 = 1.0;
double test2 = 1.0;
System.out.println(test1 == test2); //This prints true
Double test3 = 1.0;
Double test4 = 1.0;
System.out.println(test3 == test4); //This prints false
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Please have Double recognize that 1.0 equals 1.0
CUSTOMER SUBMITTED WORKAROUND :
If Double's == doesn't work, can the code for Double's == be replaced with something like this:
public static void main(String[] args){
Double test3 = 1.0;
Double test4 = 1.0;
System.out.println(test3 == test4); //This prints false (when true is expected)
System.out.println(isCloseEnough(test3, test4)); //This prints true (preferred if == gives this result rather then relying on method call)
}
//feel free to adjust the number of zeros
public static Boolean isCloseEnough(Double double1, Double double2){
Double subtract = double1 - double2;
if(subtract < .000000000000001 && subtract > -0.000000000000001){
return true;
}else{
return false;
}
}
FREQUENCY : always
double says 1.0 = 1.0
but Double says 1.0 does not equal 1.0
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
double test1 = 1.0;
double test2 = 1.0;
System.out.println(test1 == test2); //This prints true
Double test3 = 1.0;
Double test4 = 1.0;
System.out.println(test3 == test4); //This prints false
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Please have Double recognize that 1.0 equals 1.0
CUSTOMER SUBMITTED WORKAROUND :
If Double's == doesn't work, can the code for Double's == be replaced with something like this:
public static void main(String[] args){
Double test3 = 1.0;
Double test4 = 1.0;
System.out.println(test3 == test4); //This prints false (when true is expected)
System.out.println(isCloseEnough(test3, test4)); //This prints true (preferred if == gives this result rather then relying on method call)
}
//feel free to adjust the number of zeros
public static Boolean isCloseEnough(Double double1, Double double2){
Double subtract = double1 - double2;
if(subtract < .000000000000001 && subtract > -0.000000000000001){
return true;
}else{
return false;
}
}
FREQUENCY : always