浮点数进行比较
程序员文章站
2022-03-30 16:39:30
...
boolean equal(double num1, double num2) {
if (Double.isNaN(num1) || Double.isNaN(num2) || Double.isInfinite(num1) || Double.isInfinite(num2)) {
return false;
}
if ((num1 - num2 > -0.0000001) && (num1 - num2) < 0.0000001) {
return true;
} else {
return false;
}
}