Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] String to Big-Decimal conversion

Hi All,
I have the situation where I need to convert the String result returned by an if-else block in Talend that I need to convert into bigdecimal. I have tried out the  below two options and none of them seem to be working
Option 1:
(BigDecimal) ( Col1="ABC" ? Col2 : Col3)
Option 2:
(new BigDecimal(Col1="ABC" ? Col2:Col3))
In this case both Col2 and Col3 are variables of string datatype in tmap.
Please share your suggestion on whether its possible to get this type of a conversion done.
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

If field1 and field2 are BigDecimals, then you don't need to create a new one unless you are creating one for the "1" at the end.
The error you are getting is probably a nullpointerexception because you cannot use methods from a null object. You are trying to use ".toString()". If the object is null, you will get the nullpointerexception.
Why not use.....
row1.field1!=null ? row1.field1 : row1.field2!=null ? row1.field2 : new BigDecimal(1)

View solution in original post

3 Replies
Anonymous
Not applicable
Author

You are missing your row names from your "Col" names. You are also not checking for equality correctly. Assuming your row names are "row1", your code should look something like below...
new BigDecimal((row1.Col1.compareTo("ABC")==0 ? row1.Col2 : row1.Col3))
The in-line IF is contained inside brackets. This just aids readability. 
Anonymous
Not applicable
Author

I've tried using the expression below in the variable port of a tMap:
new BigDecimal((row1.field1.toString() != null ? row1.field1 0683p000009MPcz.pngrow1.field2.toString() != null ? row1.field2 : 1)))
But I get Java exception errors while testing the expression. Please note that both field1 and field are of BigDecimal datatype and I need to check if they are null.
Anonymous
Not applicable
Author

If field1 and field2 are BigDecimals, then you don't need to create a new one unless you are creating one for the "1" at the end.
The error you are getting is probably a nullpointerexception because you cannot use methods from a null object. You are trying to use ".toString()". If the object is null, you will get the nullpointerexception.
Why not use.....
row1.field1!=null ? row1.field1 : row1.field2!=null ? row1.field2 : new BigDecimal(1)