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
You could use Guava and DoubleMath#fuzzyEquals
method (since version 13.0):
public static boolean fuzzyEquals(double a, double b, double tolerance)
Returns true if a and b are within tolerance of each other. Technically speaking, this is equivalent to Math.abs(a - b) <= tolerance || Double.valueOf(a).equals(Double.valueOf(b)).
Notable special cases include:
Link to docs: https://google.github.io/guava/releases/17.0/api/docs/com/google/common/math/DoubleMath.html