int to BigDecimal

Hi

In my application there is a field "Period" of type BigDecimal. i need to check for a condition like,

($F{Period} != 0)?value1:value2

but it says, Incompatible operand types BigDecimal and int

 

and  another condition like,

($F{Period} < 0)?value1:value2

but it gives me the following error,

the operator < is undefined for the argument type(s) BigDecimal, int

 

Can you please tell me what needs to be changed in my syntax. Please post your answers soon. Its very urgent. Thanks a lot.

 

Madhan!!!!

 

mhanspmk's picture
636
Joined: Jun 18 2009 - 3:56am
Last seen: 14 years 3 months ago

3 Answers:

Try

 

($F{Period} != new BigDecimal(0))?value1:value2

 

I'm new at this Java thing so it may not work

baggypants's picture
3089
Joined: Apr 7 2009 - 12:43am
Last seen: 14 years 5 months ago

No, operators like "not equal" don't work on objects like that. Rather than converting zero to a BigDecimal, you probably need to go the other way: convert the BigDecimal to an int. Like this:

 

($F{Period}.intValue() < 0)?value1:value2

 

Regards,
Matt

 

baggypants's idea could also work, but it's probably more difficult. It would be more like this:
($F{Period}.compareTo(new BigDecimal(0)) != 0) ? value1 : value2

mdahlman's picture
37496
Joined: Mar 13 2007 - 2:43am
Last seen: 8 years 10 months ago

Try

BigDecimal secondNum = new BigDecimal(0);

if($F{Period}.compareTo(secondNum)>0))

 

Regards,

Jaf

jafarcs01's picture
162
Joined: Jan 17 2014 - 9:34pm
Last seen: 9 years 8 months ago
Feedback
randomness