Hi everyone, I am trying to convert a number with commas as thousands separators, so I guess the number shall be converted to a string and then try to apply the format.
I have found some JavaScript examples online, but when applying the solution it just converts the number to a string without the separators.
Hi @takbb thank you for the link, I have not seen that post. I downloaded the workflow and tried and it partially works, as you have to manually change the column name inside the Java Snippet node and not in the component despite that it has a dropdown list to âselectâ the column.
In summary the solution is nice but in my case I need to apply it in several columns.
As the name says, it takes a String as input, so if you have an integer/double/long column, you can convert it to String, and then back to Number like this:
But have tried Component from topic linked by @takbb and seems it works as expected although my column column is configured as input. Probably worth upgrading Component regarding this and adding multiple column supportâŚ
Hi @bruno29a , I liked your answer but it had me intrigued as I couldnât see how a numeric could remain as a Double and yet contain commas⌠following String to Number. So I had to investigate further.
So when I tried it out, firstly telling it to use â,â as thousands separator, sure enough I got thisâŚ
so⌠still puzzled, I tried using âxâ as a thousands separatorâŚ
and I still got this
And then I realised that the âthousands separatorâ on that screen indicates the thousands separator on the incoming string (if there are any) is, rather than on the outgoing number, and that the commas appearing on the output for that node are just (coincidentally) from the renderer and havenât been included in the number after all. Sadly, if you try to do anything with the number, such as String manipulation
youâll find that under the hood its still the same old double value without the formatting as it isnât really there
It looks like the String to Number would add the thousand separator regardless.
In relation to the separators not being included in the number, itâs definitely something that I would want, as the separators should be for display only - it all depends on what want to achieve in the end, and this is a personal preference.
My reason being, I donât want to lose the real value of these records, in case I need to do operations on them, and you canât process them if they physically have these separators in them. With the separators physically in them, theyâre basically strings - think of storing these values in a db table, you would want to keep them as numeric in the db, and render the separator only for display.
Hi. I have developed a component that converts selected numeric columns to String by specifying a locale. The locale controls the characters used for things like thousands separator, decimal separator, etc. Additionally, a decimal format pattern can be used for finer control of the output format (number of decimal places, whether to use scientific notation, currency formats, etc.).
I have supplied a number of predefined formats. Please give it a try and provide feedback if you are so inclined. Any suggestions for improvement appreciated.
Thanks,
Don