Format of Flow Variables for E-Mails

Hello everyone,

I try to include some results of my workflow (numbers in “double”-format) into the body of an e-mail.
I’ve used the “Table Row to Variable” node which transforms the values from my final table into flow variables, but unfortunately the variable values are shown in the exponential format, e.g. 2.875633E7 instead of 28,756,330.00.

Does anybody know how to fix this so I can show the standard double values in the e-mail body?

Thank you!

Best regards,
Daniel

Hi @DanielPressler ,

Welcome to the community! An interesting problem .The default handling of numerics can be painful can’t they!

Like you I tried a number of nodes with variations on expressions to try to force it to remain as 2 decimal places. My thoughts are that to achieve what you needed the result would have to end up being a String flow variable, but all the regular nodes for doing conversion to String automatically resulted in the Scientific notation that you obviously don’t want.

So instead, I resorted to a Java Snippet to force the conversion to String the way you need it.

In the snippet, you can change c_value to the name of your column (but prefixed with c_ as that is how the snippets work. (I added a .56 on the end of my example rather than .00 to see that it worked for 2 signficant digits. )


You can change the name of the output variable in the panel at the bottom. If anybody knows a “standard node” way of doing this, hopefully they’ll chip in, but for the moment I hope this helps you with your problem.

Please see attached workflow.

Hope that helps

KNIME_Double to 2dp String flow variable.knwf (9.3 KB)

EDIT:
If you also want the commas retained in the number, an alternative java snippet is here, using DecimalFormat class and returning in #,###,###.## format

KNIME_Double to 2dp String flow variable 2.knwf (9.5 KB)

2 Likes

see also…

:wink:

1 Like

Hi @takbb ,

the Java Snippet works perfect, thank you very much for providing this.

It would be easier to have a “standard node” solution but I’m kind of happy that it was not a trivial problem I have struggled with and that you could solve it anyway.

Cheers,
Daniel

2 Likes

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