on 10-25-2007 2:34 PM
How do we compare 2 value attributes of type Bigdecimal?
I have 2 quantity fields,i need to compare them.
Please help.Marks assured.
Hi ,
Following is the code, you can use:-
Bigdecimal dec1;
Bigdecimal dec2;
int value=dec1.compareTo(dec2);
if(value==1)
system.out.println("dec1 is greater than dec2");
if(value==-1)
system.out.println("dec1 is less than dec2");
if(value==0)
system.out.println("dec1 is equal to dec2");
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 Supriya,
Use the method
public int compareTo(BigDecimal val)
Compares this <tt>BigDecimal</tt> with the specified
<tt>BigDecimal</tt>. Two <tt>BigDecimal</tt> 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:
<tt>(x.compareTo(y)</tt> <<i>op</i>> <tt>0)</tt>, where
<<i>op</i>> is one of the six comparison operators.
@param val <tt>BigDecimal</tt> to which this <tt>BigDecimal</tt> is
to be compared.
@return -1, 0, or 1 as this <tt>BigDecimal</tt> is numerically
less than, equal to, or greater than <tt>val</tt>.
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi! Supriya,
Bigdecimal class has a method
public int compareTo(BigDecimal val)
Using this u can comapre two values of type bigdecimal.
regards,
Mithileshwar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.