I want to find out how to add commas to a string of numbers, ex. 1234567890 to 1,234,567,890. I saw a previous thread on this but the link to the solution was broken.
You need to add comma then <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink"> and some expression >>> https://www.dropbox.com/s/vsuh3hd8k6yd6 ... .capx?dl=0
You need to add comma then <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink" /> and some expression >>> dropbox.com/s/vsuh3hd8k6yd6 ... .capx?dl=0
The code works well for numbers 1,000 and 1,000,000 but the code adds an extra comma at the end of numbers like 100,000. Also, the code doesn't work well with numbers less than 1,000. Constantly adding unnecessary commas everywhere.
Develop games in your browser. Powerful, performant & highly capable.
The following regular expression will match positions which need a comma inserted.
(\d)(?=(\d{3})+$)[/code:f0idjxqc] So the following RegexReplace should do the trick : [code:f0idjxqc]RegexReplace(str(value), "(\d)(?=(\d{3})+$)", "g", "$1,")[/code:f0idjxqc] Note that it will only work with integers.
The following regular expression will match positions which need a comma inserted. (\d)(?=(\d{3})+$)[/code:wpzipeuw] So the following RegexReplace should do the trick : [code:wpzipeuw]RegexReplace(str(value), "(\d)(?=(\d{3})+$)", "g", "$1,")[/code:wpzipeuw] Note that it will only work with integers.
(\d)(?=(\d{3})+$)[/code:wpzipeuw] So the following RegexReplace should do the trick : [code:wpzipeuw]RegexReplace(str(value), "(\d)(?=(\d{3})+$)", "g", "$1,")[/code:wpzipeuw] Note that it will only work with integers.
Thanks, the code works perfectly.
I revised and updated the example. Now it should show correct display >>> https://www.dropbox.com/s/vsuh3hd8k6yd6 ... .capx?dl=0
The code works a bit better but its still broken with numbers less than 100, like 10 or 1.
So add another condition so that it only does the comma parse if the number is bigger than 100
As suggested by mikehive the capx is fixed now. Check it again.
thanks Magistross for a very nice one-line solution!
RegexReplace(str(Variable), "(\d)(?=(\d{3})+$)", "g", "$1,")