![]() |
VOOZH | about |
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 less than, equal to, or greater than the specified BigDecimal.
Example:
1
Explanation: Since 10.5 is greater than 8.2, the compareTo() method returns 1.
public int compareTo(BigDecimal bg);
Parameters: 'bg' the BigDecimal object to be compared with the current object.
Return Value:
This example shows that compareTo() compares numeric values only and ignores scale when determining which value is greater.
1
Explanation:
BigDecimal.compareTo() considers values equal regardless of scale differences.
0
Explanation:
This example shows how BigDecimal.compareTo() determines that one value is smaller than another based on numeric value, ignoring scale.
-1
Explanation:
Note : compareTo() compares only the value, not the scale.This behavior is different from equals(), which considers both value and scale.