How to compare that sequence of doubles are all “approximately equal” in Java?

前端 未结 7 2108
感动是毒
感动是毒 2021-02-07 02:22

I have a method in java that returns a double number and I want to compare every double number that is returned every time I call the method(say 5 times), so that I can conclude

7条回答
  •  一向
    一向 (楼主)
    2021-02-07 02:48

    public static boolean almostEqual(double a, double b, double eps){
        return Math.abs(a-b)

    Where eps is measure of equality.

提交回复
热议问题