public class Main {
public static void main(String[] args) {
double x = 1 - 9.0 / 10;
if (Math.abs(x - 0.1) < 0.00001) {
System.out.println(Math.abs(x - 0.1)); //这一行有点问题
System.out.println("x is 0.1");
} else {
System.out.println("x is NOT 0.1");
}
}
}
晓蝎软件实验室
为什么在if判断里,Math.abs(x - 0.1)小于0.00001,打印出来这个值却是2.7755575615628914E-17呢?