Basically you shouldn't do exact comparisons, you should do something like this:

double a = 1.000001;
double b = 0.000001;
double c = a-b;
if (Math.abs(c-1.0) <= 0.000001) {...}
Answer from Kevin on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
July 21, 2026 - Compares two Double objects numerically. There are two ways in which comparisons performed by this method differ from those performed by the Java language numerical comparison operators (<, <=, ==, >=, >) when applied to primitive double values:
🌐
GeeksforGeeks
geeksforgeeks.org › java › double-compare-method-in-java-with-examples
Double compare() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - // Java Program to illustrate // the Double.compare() method import java.lang.Double; public class GFG { public static void main(String[] args) { // Get the two double values // to be compared Double d1 = 10d; Double d2 = 1023d; // function call to compare two double values if (Double.compare(d1, d2) == 0) { System.out.println("d1=d2"); } else if (Double.compare(d1, d2) < 0) { System.out.println("d1<d2"); } else { System.out.println("d1>d2"); } } }
Discussions

How do you compare two double values
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
11
4
October 17, 2023
Double vs BigDecimal in financial programming

Use long or big decimal. Performance problems will most probably arise elsewhere before you factor a big decimal as the culprit

More on reddit.com
🌐 r/java
105
44
May 22, 2018
How to compare two Java objects?
By convention, each Java class has an equals method that is inherited from the base Object class. The actual implementation depends on the use case. In your example, you could check that the two objects have the same values for number, color and ball. More on reddit.com
🌐 r/javahelp
8
1
July 12, 2017
Java: Comparing two numbers of type double to three decimal places using a boolean value
Try to find a math formula to solve the problem. Maybe, knowing the Math.abs() in Java will be useful ... More on reddit.com
🌐 r/learnprogramming
8
1
January 20, 2019
🌐
Baeldung
baeldung.com › home › java › java numbers › comparing doubles in java
Comparing Doubles in Java | Baeldung
December 11, 2025 - The recommended algorithm to compare double values in plain Java is a threshold comparison method.
🌐
Mtu
cclc.mtu.edu › java-doubles-and-floating-point-numbers
Java Doubles and Floating Point Numbers – CCLC
Another way to compare doubles is rounding. However, the more calculations, the greater the possibility that there will be larger rounding errors. Rounding is not always guaranteed to work. A third way to compare doubles is to use Java’s BigDecimal class to define floating point numbers.
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › javas-double-compare-method-explained-6159db37e326
Java’s Double.compare() Method Explained | Medium
December 23, 2024 - The Double.compare() method offers a consistent and reliable way to compare floating-point values in Java, handling special cases like NaN, infinities, and signed zeros with well-defined behavior.
🌐
DEV Community
dev.to › pavel_polivka › double-comparison-in-java-1b7
Double comparison in Java - DEV Community
May 12, 2021 - Simply, we will subtract those doubles, make absolute value, and compare if the result is smaller than some very small number. double epsilon = 0.000001d; boolean result = Math.abs(firstDouble - secondDouble) < epsilon; System.out.println(result); ...
🌐
Caff
caff.de › posts › double_comparison
de·caff · Double Equality
February 10, 2023 - The standard solution in Java is falling back to java.lang.Double#compare(double, double).
🌐
Coderanch
coderanch.com › t › 549438 › java › comparing-doubles-greater
comparing doubles with less than or greater than (Java in General forum at Coderanch)
August 16, 2011 - Chris Zaremba wrote:I understand that you shouldn't use equals for comparing two double values but does the same hold true for comparing a double to a literal using less than and greater than? Yes. campbell@computer_name:~/java$ java DoubleComparison 1.0 0.1 10 d3 < d1: ...
🌐
Scaler
scaler.com › home › topics › java double compare()
Java Double compare() - Scaler Topics
May 4, 2023 - The compare() method in Java Double class is a static method used to compare two double values.
🌐
EqualsVerifier
jqno.nl › equalsverifier › errormessages › double-equals-doesnt-use-doublecompare-for-field-foo
Double: equals doesn’t use Double.compare for field foo - EqualsVerifier
3 weeks ago - You should never use == to compare doubles or floats in an equals method. Always use Double.compare or Double.compareTo instead.
🌐
InterviewBit
interviewbit.com › java-interview-questions
90+ Core Java Interview Questions and Answers | Freshers & experienced
Java supports primitive data types - byte, boolean, char, short, int, float, long, and double and hence it is not a pure object oriented language.
Published: May 4, 2026
🌐
Playwright
playwright.dev › locator
Locator | Playwright
Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way to find element(s) on the page at any moment. A locator can be created with the page.locator() method.
🌐
Baeldung
baeldung.com › home › java › core java › the double colon operator in java
The Double Colon Operator in Java | Baeldung
May 29, 2025 - As we’re starting to see, the double colon operator – introduced in Java 8 – will be very useful in some scenarios, and especially in conjunction with Streams.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › double_compare.htm
Java - Double compare() method
The Java Double compare() method compares the two specified double values. The sign of the integer value returned is the same as that of the integer that would be returned by the call − new Double(d1).compareTo(new Double(d2)) Following is the
🌐
LabEx
labex.io › tutorials › java-how-to-compare-double-values-based-on-their-binary-format-in-java-414887
How to compare double values based on their binary format in Java | LabEx
This tutorial will guide you through the process of comparing double values in Java based on their binary format. Understanding the representation of double in Java and the nuances of floating-point comparison are crucial for accurate and reliable comparisons.