Float
public static void main(String[] args) { Float x = 12.4F; Float y = 12.4F; // 比较对象地址 System.out.println(x == y); // 比较值,不准确,会丢失精度 System.out.println(x.equals(y)); // x 与 y 的绝对值 System.out.println(Math.abs(x - y)); // 比较精度比值的精度多一位即可 if (Math.abs(x - y) > .01) { System.out.println("不相等"); } else { System.out.println("相等"); } }