绝对误差法

public class FloatComparator {
	public static void main(String[] args) {
		double a = 2.00 - 1.10;
		double b = 0.90;
		System.out.println("a="+a);
		System.out.println("b="+b);
		System.out.println(isEqual(a, b));
		System.out.println(a==b);
	}

	public static boolean isEqual(double a, double b) {
		final double epsilon = 0.000000001;
		return Math.abs(a - b) < epsilon;
	}
}

输出结果:

a=0.8999999999999999
b=0.9

true
false

你可能感兴趣的:(绝对误差法)