Casting doubles to string if not already a string

Dear community,

sorry for the weird topic - couldn’t think of a better one.
Situation

  • There are postings on a monthly base.
  • Postings may have a Tax Registration Number (TRN) or not (i.e., NULL / MISSING is a valid state).
  • Transactions are transferred to the KNIME workflow in 6 files of different structure.

Observation

  • The TRN is a string value that starts usually with two letters followed by 11 significant digits.
  • It may occur, that a TRN is a 13 digit number (no leading letters) - this is a valid state.
  • If a file contains only numerical TRN, KNIME sets “double” as type.

Challenge

  • In case KNIME sets the type to double, I need to cast this to string. Since the type may change from run to run, I need a kind of a ‘conditional’ cast.

Any suggestions?

Kind regards,

Patrick

Column Rename Node offers a cast option - however, it adds an exponential formatting at the end (e.g., “E14”…).

Does anyone has an idea how to solve that?

Have you thought about forcing the column to a string while importing the data? Or is the import in another format?

Hey @mlauber71,

I would love to do so - however, the XLS reader only offers numerical types…

Hi @Patrick1974,
did you try the Number to String node? It should do exactly what you want, the double values are turned into String values without any scientific formatting.

To do a “Conditional Cast” you could use a Column Splitter node with a type split:

Route it through the Number to String node as follows and join it all up again
Selection_011.
This will also work if no matching columns are available.

BTW: Using the Column Rename node for type changes often leads to weird results, I can not recommend ever doing that.

best,
Gabriel

3 Likes

Hey @gab1one,

nice idea, will try that one! Actually, I use the number to string node. However, in case KNIME identifies the column already as string, execution stops. That’s where your idea kicks in! I like your approach.

Kind regards,

Patrick

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.