Number Rounder (Standard String) Removing Thousands Separator

Good day

In my exports I usually need to generate floats with 2 decimal places and in string format so that the full decimals always show even when “.00“.

I usually accomplish this by using the Number Rounder node and setting the output mode as “Standard String“. This will generate results like “123.00“, which is what I want.

I now need to include the thousands separators, e.g. “20,001.00“, but it seems the number rounder in standard string combination removes the separator.

Other than using a column expression node to manually set them depending on the length, is there a way to keep the thousands separator when converting to string while still forcing the 2 decimal places?

2 Likes

@William_Alexand ChatGPT suggested a Python code to do that … though

1 Like

In my opinion there’s a missing option in the number to string node for that. In the meanwhile you can use the string manipulation node with the setting:

regexReplace(string($yourColumn$), “\B(?=(\d{3})+(?!\d))”, “,”)

image

3 Likes

You can also do it with a java call using this String Manipulation “hack”:

string(
new java.text.DecimalFormat(“#,##0.00”).format($column1$)
)

2 Likes

This is another option in a Simple Java Snippet

// Create custom symbols
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator(',');
symbols.setDecimalSeparator('.');

// Apply pattern with custom symbols
DecimalFormat df = new DecimalFormat("#,##0.####################", symbols);
return df.format($my_number$);
2 Likes

That’s sneaky :smiley:

I didn’t even know that there’s a tunnel to java

1 Like

@ActionAndi this may be of interest… :smiley:

So cool. This “string manipulation node” is one of my favorites. Now even more :slight_smile:

1 Like