new BigDecimal(0.82) is not actually 0.82, because you're passing a double value -- the double closest to 0.82, which is not exactly 0.82 -- to the constructor, so new BigDecimal(0.82) is a BigDecimal equal to the double closest to 0.82.

Instead, use new BigDecimal("0.82").

Answer from Louis Wasserman on Stack Overflow
🌐
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 - The reason why the equals method fails, is because the equals() method in the BigDecimal will consider the ‘scale’ of the two numbers which are 1, and 2 respectively (which are not equal) — and hence will not be equal. Use compareTo() instead.
🌐
Igor's Techno Club
igorstechnoclub.com › java-bigdecimal
The Pitfalls of Comparing BigDecimals in Java | Igor's Techno Club
This can lead to surprising results when comparing BigDecimals with different scales. ... BigDecimal zero1 = new BigDecimal("0"); BigDecimal zero2 = new BigDecimal("0.0"); System.out.println(zero1.scale()); // Output: 0 System.out.println(zero2.scale()); // Output: 1 System.out.println(zero1.equals(zero2)); // Output: false · In this case we pass a Java String to the BigDecimal constructor to create a BigDecimal objects, but even though both zero1 and zero2 represent the value zero, their scales differ.
🌐
Tutorialspoint
tutorialspoint.com › home › java/math › bigdecimal compareto in java
BigDecimal compareTo in Java
September 1, 2008 - The java.math.BigDecimal.compareTo(BigDecimal val) compares the BigDecimal Object with the specified BigDecimal value. Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this 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 - For example, stripping the trailing ... this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method....
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 7 )
For example, stripping the trailing ... this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method....
🌐
Medium
bterczynski.medium.com › comparing-bigdecimals-for-equality-71037fa2ee1d
Comparing BigDecimals for Equality | by Brian Terczynski | Medium
January 23, 2022 - 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 ...
Find elsewhere
Top answer
1 of 3
13

You need to use the String constructor to get the correct scales, because the BigDecimal(double) will get the small scale possible

translates a double into a BigDecimal which is the exact decimal representation of the double's binary floating-point value. The scale of the returned BigDecimal is the smallest value such that (10scale × val) is an integer.

More precision about the documentations :

BigDecimal.equals(Object)

Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).

BigDecimal.compareTo(BigDecimal)

Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method. 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) 0), where is one of the six comparison operators.

You will find that the equals use the scale for the comparison, giving some "strange" result.

BigDecimal bd1 = new BigDecimal("2"); //scale 0
BigDecimal bd2 = new BigDecimal("2.00"); //scale 2

bd1.equals(bd2); //false
bd1.compareTo(bd2); //0 => which means equivalent
2 of 3
3

It's better to use compareTo for BigDecimal. This method will return a number greater than zero if a > b, 0 if a == b, and less than zero if a < b

🌐
Baeldung
baeldung.com › home › java › java numbers › check if bigdecimal value is zero
Check if BigDecimal Value Is Zero | Baeldung
January 16, 2024 - Next, let’s see a couple of approaches to solve the problem. The BigDecimal class implements the Comparable interface. So, we can use the compareTo method to compare two BigDecimal objects’ values.
🌐
Coderanch
coderanch.com › t › 479145 › java › Comparing-BigDecimals
Comparing BigDecimals (Java in General forum at Coderanch)
Which is the better way to check if two BigDecimals are equal?Both methods 1 and 2 seem to work fine. And both are completely unreadable and ugly. Yet which one is better? Another problem is with hash codes. If I try to do it like this:I get m == false. Because a and b have different scales, they also produce different hash code. Can you offer me a good way to get equal hash codes for a and b? This seems to work, but I'm not sure: ... I would go for the compareTo method because then you're comparing the values.
🌐
Coderwall
coderwall.com › p › rih_aa › bigdecimal-equals-scale-comparison
BigDecimal .equals scale comparison (Example)
February 25, 2016 - I ran into an issue this morning with the java BigDecimal equals implementation. When comparing the two BigDecimal objects
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-compareto-function-in-java
BigDecimal compareTo() Function in Java - GeeksforGeeks
June 25, 2018 - Java Collection · Last Updated : 9 Jan, 2026 · The BigDecimal.compareTo() method compares two BigDecimal objects based on their numerical value only, ignoring scale differences, and returns an integer indicating whether the current value is ...
🌐
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.
🌐
Lustforge
lustforge.com › 2011 › 07 › 14 › comparing-bigdecimals-with-round-and-setscale
Comparing BigDecimals with Round and SetScale · Joseph Lust
// constant int myNumDecimals = 2; // do some math, round to desired number decimal places BigDecimal myValA = someBD1.multiply(someBD2).setScale( myNumDecimals, RoundingMode.HALF_UP); BigDecimal myValB = someBD3.divide( someBD4).setScale( myNumDecimals, RoundingMode.HALF_UP); // compare - has three int returns: [-1,0,1] -> [<,==,>] if( myValA.compareTo(myValB) == 0 ) { System.out.println("They match!"); }
🌐
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