Java Double Number Almost Equal almostEqual(double a, double b, double delta)

Here you can find the source of almostEqual(double a, double b, double delta)

Description

Check whether two floating point values match with a given precision.

License

Open Source License

Parameter

Parameter Description
a First value
b Second value
delta Precision

Return

true if the difference of a and b is smaller or equal than delta, otherwise false

Declaration

public static boolean almostEqual(double a, double b, double delta) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  ww  .  ja  v  a 2 s .  c o  m*/
     * Check whether two floating point values match with a given precision.
     *
     * @param a     First value
     * @param b     Second value
     * @param delta Precision
     * @return {@code true} if the difference of <i>a</i> and <b>b</b> is
     *         smaller or equal than <i>delta</i>, otherwise {@code false}
     */
    public static boolean almostEqual(double a, double b, double delta) {
        return Math.abs(a - b) <= delta;
    }
}

Related

  1. almost(double a, double b, double prec)
  2. almostEqual(double a, double b)
  3. almostEqual(double[][] a, double[][] b, double delta)
  4. almostEqual(final double aDouble, final double otherDouble)
  5. almostEquals(double d1, double d2)
  6. almostEquals(double d1, double d2, double epsilon)