# Manipulation of numbers

Hello alltogether,
the Numbers in a table output (here a groupby-Table) look like this: 123904

If this is a currency it would be nicer to format it like this: 123.905,00 €

Is there a node for such manipulations ?

Greetings
Berthold

You can also use the Number to String node.

Best, Iris

1 Like

I tried the node: number to string.
It converts a number to a string, but this is not my point.​

I would like to format the number in the way, I mentioned above.

That means: The output of 1234 should be: 1.234,00 €

Is that possible with the number to string node.
(Sorry, I am new in knime)

Greetings
Berthold

OK I figured it out by myself.

A small Java-Snippet does the work.

----------schnipp---------
umsatz=\$Umsatz\$;
Locale caLoc = new Locale("de", "DE");
NumberFormat n = NumberFormat.getCurrencyInstance(caLoc);
String s = n.format(umsatz);
return s;
-----------schnapp---------------​

Berthold Lausch

I also need this help and I dont understood the tips above.

Step by step

1. Use the Round Double node in Manipulations -> Column -> Convert & replace, configure this to select the source columns containing doubles, and select the precision (2 digit), the type of string you want this to be returned (plain string), and the rounding type. This will convert the column of double, eg, from a double number 123.4565 to a string 123.46 if 2 digit precision, rounding half_up is chosen.

2. if you need the thousand separators, then the easiest way is to use java to format a string. Look up java String.format to see the format setting. To have two decimal places and thousand separators, you want  String.format("%,.2f%n", INPUT_NUMBER). The % indicates this is a formatting, the "," is for thousand separator, ".2f" is to format a floating point number with 2 decimal places.

example workflow attached

David

2 Likes

Thank you David Ko !!!

Perfect

Thank you David Ko !!!

Perfect

Just an addition re rounding: For precision reasons you may want to avoid using "double" formatted numbers for currency transactions - much easier to express everything in "integer" cents until the last moment.

Cheers
E

I have used the Java Snippet with a different set of code.

See the attached PNG image of the Java Snipped Configuration Screen that converted Invoice Amount to formated Currency String with mask "\$###,###,###,##0.00"

Cheers!

Hi, this is exactly what I was searching for as well. I’ve been reading different solutions to the above-mentioned problem, but I can’t seem to understand, why the solutions are all string based. Why would anyone want to have numbers formatted as strings? If I use String to Number Node/Table Manipulators etc., the formatting goes off.

So the question is, how can I have my numbers formatted with this code and have them later exported through Excel Writer as integers.

First of all, you need to understand what kind of information you have, it’s a number, string, data…

After that, you can convert it on different kind using “String Manipulation node” to change it to another format, or make a calculation if it’s a number with “Math Formula node”.

As a example below, I created a table with 2 columns “Costs” and “DIV” to make a simple divison.

the “Math Formula node” can prevent it ant convert to int number or not, as you wish… My suggestion is to put the infomation into another field (append column) as a result.

Desactivated

Activated

At the Math Formula yet, you can use rounding functions if you need it too.

If you have a string information and need to convert to a number, use de “String Manipulation node” to it:

As you can see, you can convert string to boolean, double, int e long!

I hope answer this question properly.

Thanks all!!!