Mathematical.Num() in Expression Builder

One Star

Mathematical.Num() in Expression Builder

I am trying to format a string into a specific format only if it is numeric.
I am using the following expression in the tmap.
Mathematical.NUM(row.number) ? String.format("%010d", Double.parseDouble(row.number)) : row.number 
I am getting a compilation error: Type Mismatch: Cannot convert int to boolean.
Moderator

Re: Mathematical.Num() in Expression Builder

Hi,
Mathematical.NUM(row.number) ? String.format("%010d", Double.parseDouble(row.number)) : row.number

Could you please elaborate your case with an example with input and expected output values? 
Would you mind posting your tMap editor screenshot into forum?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Mathematical.Num() in Expression Builder

You are getting that error since that 1-line if-else statement needs a BOOLEAN expression at the left side, but Mathematical.NUM returns an INTEGER value 1 if the parameter passed is a numeric data type, or 0 if otherwise. So you have to add a bit of code to your decision statement, such that it checks if the returned value is equal to 1 or not (added code in red bold):
Mathematical.NUM(row.number) == 1? String.format("%010d", Double.parseDouble(row.number)) : row.number