BigDecimal Comparison
In this chapter you will learn:
Compare two BigDecimal
int compareTo(BigDecimal val)
Compares this BigDecimal with the specified BigDecimal.booleanequals(Object x)
Compares this BigDecimal with the specified Object for equality.
compareTo(BigDecimal val) returns:
Return | Meaning |
---|---|
-1 | this BigDecimal is numerically less than val |
0 | this BigDecimal is numerically equal to val |
1 | this BigDecimal is numerically greater than val. |
Use compareTo method
import java.math.BigDecimal;
/*j ava 2 s . c om*/
public class Main {
public static void main(String[] args) {
BigDecimal first = new BigDecimal(-1f);
BigDecimal second = new BigDecimal(10f);
System.out.println(first.compareTo(second));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » BigDecimal BigInteger