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 

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog