Formatting numbers for webportal views

Hi fellows,

I had quite some trouble to display numbers in the webportal in readable fashion with a thousand-seperator " , " within the “Table Editor” node.

Generically, it seems that number formats don’t come with seperators (except decimal seperators, which you can easily check in the node configuration itself. Would be cool to have this feature for thousand seperators as well.) (see example screenshot 1). The number to string does not work, as a decimal seperator is set straight after the first number. Furthermore, the number formats are shown with exponential convention.(see example screenshot 2) I also tried the round double node as workaround, which also did not solve the thousand seperators issue.

Screenshots:

  1. Normal number Format in Table Editor View:
    image

  2. Format after number to string in Table Editor View:

image

The only thing left was to scale numbers down to avoid thousand seperators in the first place.

image

Is there any solution to this? Can CSS help out here? I found the class “.knime-double” which looked promising, but my CSS know how is limited.

image

Or maybe I am missing something straightforward here?
Looking forward to ideas and solutions.

Thanks and best regards,
Stiefel

Hi @Residentstiefel,

I was able to add the commas in using the Column Expression Nodes and some quick JavaScript with RegEx. Hopefully this is what you were looking for.

Regards,
Wali Khan

3 Likes

Hi @wkhan,

This helps absolutely for the time being! Thanks alot!
Though I was hoping for a more “low code friendly” solution, as it is quite difficult to explain to colleagues that we want to use low code tools, and then the solution is JS / R / Python etc. based. Even though this means of course just copying the col. expressions node into the workflow for this instance.

Would it be a solution to include this option into the table view nodes as well, since there are already formatter tabs available? Or does it make sense to make this feature available in the number to string formatter node? The other way around, this option is included (in the string to number node, obviously to identify the number correctly)? This would be very helpful when formatting numbers in emails, reporting etc. as well.

Anyways, thanks alot for the solution :slight_smile: We can definitely work with it!

Best regards,
Stiefel

1 Like

Hi @Residentstiefel , the String to Number node usually have the options to set the thousand separator:

With this node, you don’t need any “coding” :slight_smile:

Here’s what a test workflow looks like:

And here’s the workflow: Thousand separator.knwf (7.8 KB)

2 Likes

Nice one @bruno29a! I read the original post as keeping the data as a string for some reason :see_no_evil:

Hi @wkhan , it could still be that the data needs to be kept as string lol. I just did not see the restriction, so hopefully the data does not need to be kept as string :smile:

1 Like

Hi Bruno, hi wkhan

This is exactly the reason why I have to format numbers to a string: The web portal does not portray doubles in a readable fashion with thousand separators, in contrast to the generic knime data preview function!
This also applies for email reporting: knime preview looks fine for doubles. But the eventual email contains number format like e g. 1224005326,2. Pretty hard to read…

Best regards,
Stiefel

Hi @Residentstiefel , I see. Then what @wkhan suggested would be the solution

1 Like

Hello there!

Seems not as it’s not supported. See here.

Another idea is to go with Java in Java Snippet (simple) with following piece of code:

String formNum= String.format("%1$,.2f", $YourColumn$);
return formNum;

Pretty simple and understandable although involves some coding. See here for more:

Agree it would be nice for Number to String to feature separator configuration actually (will create ticket; Internal reference: AP-16673). And probably same goes for JavaScript View/Editor nodes…

Br,
Ivan

3 Likes

That’s awesome! Thanks alot @ipazin!

1 Like

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