To be short:

firstBigDecimal.compareTo(secondBigDecimal) < 0   // "<"
firstBigDecimal.compareTo(secondBigDecimal) > 0   // ">"    
firstBigDecimal.compareTo(secondBigDecimal) == 0  // "=="  
firstBigDecimal.compareTo(secondBigDecimal) != 0  // "!="  
firstBigDecimal.compareTo(secondBigDecimal) >= 0  // ">="    
firstBigDecimal.compareTo(secondBigDecimal) <= 0  // "<="    
Answer from torina on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-compareto-function-in-java
BigDecimal compareTo() Function in Java - GeeksforGeeks
June 25, 2018 - import java.math.BigDecimal; class GFG { public static void main(String[] args) { BigDecimal b1 = new BigDecimal("10.5"); BigDecimal b2 = new BigDecimal("8.2"); System.out.println(b1.compareTo(b2)); } } ... Explanation: Since 10.5 is greater ...
🌐
Educative
educative.io › answers › how-to-compare-two-bigdecimals-in-java
How to compare two BigDecimals in Java
A BigDecimal consists of a 32-bit integer scale; it is used to handle very large and very small floating-point numbers. Java provides the built-in function compareTo() which compares the two BigDecimals.
🌐
Medium
bterczynski.medium.com › comparing-bigdecimals-for-equality-71037fa2ee1d
Comparing BigDecimals for Equality | by Brian Terczynski | Medium
January 23, 2022 - So when I looked at the actual value of BigDecimal.ZERO in the debugger, it came up as this: Note that one field in particular is different than the above: the scale. It’s 0 in this case, whereas above it’s 1 . Since they’re different, the == operation does not consider them to be equal. Instead, the Javadoc suggests that compareTo be used, because in this case I don’t actually care about the scale used to represent the number; I only care that the operation’s value is zero, regardless of what scale is used to represent it.
🌐
Tutorialspoint
tutorialspoint.com › home › java/math › bigdecimal compareto in java
BigDecimal compareTo in Java
September 1, 2008 - ... This method returns -1 if the BigDecimal is less than val, 1 if the BigDecimal is greater than val and 0 if the BigDecimal is equal to val ... The following example shows the usage of math.BigDecimal.compareTo() method.
🌐
Baeldung
baeldung.com › home › java › core java › bigdecimal equals() vs. compareto()
BigDecimal equals() vs. compareTo() | Baeldung
May 2, 2024 - In some specific cases, we want to distinguish numbers by their precision; for example, in physics, we tend to treat numbers with different precisions as different. However, we have additional reasons for such behavior in the BigDecimal class. First of all, the representations of the numbers aren’t the same. The scale is stored in a separate field and defines the floating point’s position: public class BigDecimal extends Number implements Comparable<java.math.BigDecimal> { //... private final int scale; //... }
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
October 20, 2025 - This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.
🌐
Igor's Techno Club
igorstechnoclub.com › java-bigdecimal
The Pitfalls of Comparing BigDecimals in Java | Igor's Techno Club
To avoid this pitfall and compare BigDecimals based on their numerical values, you have a couple of options: Use the compareTo() method: The compareTo() method compares the numerical values of BigDecimals, regardless of their scales.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.math.bigdecimal.compareto
BigDecimal.CompareTo(BigDecimal) Method (Java.Math) | Microsoft Learn
Java.Math · Assembly: Mono.Android.dll · Important · Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here. Compares this BigDecimal with the specified BigDecimal. [Android.Runtime.Register("compareTo", "(Ljava/math/BigDecimal;)I", "GetCompareTo_Ljava_math_BigDecimal_Handler")] public virtual int CompareTo(Java.Math.BigDecimal?
🌐
Java2Blog
java2blog.com › home › core java › bigdecimal › bigdecimal compareto
BigDecimal compareTo - Java2Blog
January 12, 2021 - CompareTo method returns -1,0,1 -1 : First BigDeicmal is less than second BigDecimal 0 : First BigDecimal is equal to second BigDecimal 1 : First BigDecimal is greater than second BigDecimal · Let’s see compareTo method with the help of example.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 7 )
This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.
🌐
Tabnine
tabnine.com › home page › code › java › java.math.bigdecimal
java.math.BigDecimal.compareTo java code examples | Tabnine
/** * Canonicalize the current latitude and longitude values such that: * * <pre> * -90 &lt;= latitude &lt;= +90 - 180 &lt; longitude &lt;= +180 * </pre> */ private void canonicalize(DecimalType aLat, DecimalType aLon) { latitude = flat.add(aLat.toBigDecimal()).remainder(circle); longitude = aLon.toBigDecimal(); if (latitude.compareTo(BigDecimal.ZERO) == -1) { latitude.add(circle); } latitude = latitude.subtract(flat); if (latitude.compareTo(right) == 1) { latitude = flat.subtract(latitude); longitude = longitude.add(flat); } else if (latitude.compareTo(right.negate()) == -1) { latitude = flat
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 17 & JDK 17)
January 20, 2026 - This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.
🌐
Linux Hint
linuxhint.com › compare-two-bigdecimals-in-java
How to Compare Two BigDecimals in Java
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
IncludeHelp
includehelp.com › java › bigdecimal-compareto-method-with-example.aspx
Java BigDecimal compareTo() Method with Example
... When (this BigDecimal) == (BigDecimal ob), it returns 0. When (this BigDecimal) < (BigDecimal ob), it returns -1. When (this BigDecimal) > (BigDecimal ob), it returns 1. ... // Java program to demonstrate the example // of int compareTo() method of BigDecimal import java.math.*; public ...
🌐
Coderanch
coderanch.com › t › 375912 › java › BigDecimal-compareTo
BigDecimal compareTo() problem (Java in General forum at Coderanch)
Java in General · Joe Busch · Greenhorn · Posts: 12 · posted 20 years ago · Number of slices to send: Optional 'thank-you' note: Send · I have 3 BigDecimal variables: a, b and c. I then do the following test: if( a.add(b).compareTo(c) == 0 ) a = 49.9900000000000001827363995 b = 50.01 c = 100 ...
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-6321015
BigDecimal should have comparison methods that return a ...
CUSTOMER SUBMITTED WORKAROUND : public boolean isGreaterThan(BigDecimal other) { return this.compareTo(other) > 0; } public boolean isGreaterOrEqual(BigDecimal other) { return this.compareTo(other) >= 0; } public boolean isLessThan(BigDecimal other) { return this.compareTo(other) < 0; } public ...
🌐
Oreate AI
oreateai.com › blog › beyond-simple-equality-mastering-bigdecimal-comparisons-in-java › 07729979fb9d362e717c9fd973b709a4
Beyond Simple Equality: Mastering BigDecimal Comparisons in Java - Oreate AI Blog
January 27, 2026 - Learn how to accurately compare BigDecimal values in Java using the compareTo() method, understanding its numerical comparison logic and how it handles scale differences.
🌐
Simplesolution
simplesolution.dev › java-compare-two-bigdecimal-values
Java Compare two BigDecimal values
import java.math.BigDecimal; public ... The following Java example to show you the compareTo() method return -1 when the value is less than the value it compare to....
🌐
Medium
medium.com › beingabetterdeveloper › comparing-bigdecimal-s-with-different-scales-2901bf26538f
Comparing BigDecimal(s) with different scales | by Vineeth Venudasan | Being A Better Developer | Medium
May 26, 2018 - @Test public void testBigDecimal() { BigDecimal first = new BigDecimal( “10.0” ); BigDecimal second = new BigDecimal( “10.00” ); assertThat( first ).isEqualTo( second ); // will fail }