Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
pawe84
Creator

syntax to compare BigDecimal if it's greater than x

Hi everyone I'M struggling with the syntax.

 

I have a field which ist called "achievement", data type BigDecimal.

Inside are values like : 0.756

 

Now I just want to create a condition  in tmap like:  if achievement>= 0.7 then 100 else 0

 

I tried this but something isn't correct:

(row1.achievement.compareTo(BigDecimal.valueOf(>=0.7)))? new BigDecimal(100) : new BigDecimal(0)

 

Thanks for any hints.

 

Labels (2)
1 Solution

Accepted Solutions
manodwhb
Champion II

@pawe84 ,check the below expression.

 

(row4.newColumn.compareTo(BigDecimal.valueOf(0.7))==1 && row4.newColumn.compareTo(BigDecimal.valueOf(1)) < 0 ) ?new BigDecimal(100 )  :     ((row4.newColumn.compareTo(BigDecimal.valueOf(1))==1 && row4.newColumn.compareTo(BigDecimal.valueOf(1.2))<0)?new BigDecimal(200):new BigDecimal(0))

View solution in original post

5 Replies
fdenis
Master

firstBigDecimal.compareTo(secondBigDecimal) < 0 // "<"
firstBigDecimal.compareTo(secondBigDecimal) > 0 // ">"
firstBigDecimal.compareTo(secondBigDecimal) == 0 // "=="
firstBigDecimal.compareTo(secondBigDecimal) >= 0 // ">="

so use:
BigDecimal.valueOf((row1.achievement.compareTo(BigDecimal.valueOf(0.7)>=0)? 100 : 0)
pawe84
Creator
Author

Thanks but when I try this statement I'll get always this error

 

 

0683p000009M7hv.png

manodwhb
Champion II

@pawe84 ,check the below condition.

 

row1.newColumn.compareTo(BigDecimal.valueOf(0.7))>=1?new BigDecimal(100) : new BigDecimal(0)

 

 

pawe84
Creator
Author

Thanks it's working.

 

How would the syntax be if there's the following condition

 

if achievement>=0.7 and <1 then 100

elseif achievement>=1 and <1.2 then 200

else

0

end

manodwhb
Champion II

@pawe84 ,check the below expression.

 

(row4.newColumn.compareTo(BigDecimal.valueOf(0.7))==1 && row4.newColumn.compareTo(BigDecimal.valueOf(1)) < 0 ) ?new BigDecimal(100 )  :     ((row4.newColumn.compareTo(BigDecimal.valueOf(1))==1 && row4.newColumn.compareTo(BigDecimal.valueOf(1.2))<0)?new BigDecimal(200):new BigDecimal(0))