on 10-26-2007 7:06 PM
Hi All,
I want to use compareto( ) method in my application. I have two BigDecimal values .How can I compare them and explain the method's functionality clearly...
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks all.........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use the method compareTo
public int compareTo(BigDecimal val)
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) <op> 0), where <op> is one of the six comparison operators.
Specified by:
compareTo in interface Comparable<BigDecimal>
Parameters:
val - BigDecimal to which this BigDecimal is to be compared.
Returns:
-1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val.
Thanks
Smitha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use following method.
public int compareTo(BigDecimal val);
Ex.BigDecimal val1,val2;
val1.compareTo(BigDecimal val2);
it will return -1, 0, or 1 as this val1 is numerically less than, equal to, or greater than val2.
Regards,
Praveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use the method public int compareTo(BigDecimal val) 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) <op> 0), where <op> is one of the six comparison operators. @param val BigDecimal to which this BigDecimal is to be compared. @return -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val.
Regards Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.