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 OverflowTo 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 // "<="
Every object of the Class BigDecimal has a method compareTo you can use to compare it to another BigDecimal. The result of compareTo is then compared > 0, == 0 or < 0 depending on what you need. Read the documentation and you will find out.
The operators ==, <, > and so on can only be used on primitive data types like int, long, double or their wrapper classes like Integerand Double.
From the documentation of compareTo:
Compares this
BigDecimalwith the specifiedBigDecimal.Two
BigDecimalobjects 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) <op> 0), where<op>is one of the six comparison operators.Returns: -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val.