var/regex/comma_expression = new("(\\d)(?=(\\d{3})+$)","g") // hidden init proc, I know I know.
#define commafy(x) comma_expression.Replace(num2text(x,12),"$&,")
Example:
var/number = 150255
src << commafy(number) // 150,255
src << commafy(9999999) // 9,999,999
(Note: This is the first time I've done anything with regex, it can probably be improved and I don't know it, so let me know!)
Edit: Updated to globalize the /regex and turn the proc into a #define
Give an example of before the regex, and example of the after, please.
Just incase I did hit the nail on the head with 1000 -> 1,000
the regex is
Which results in "1,000"
This works by finding the spot where the comma should go (numbers before it, 3 behind it) and substituting a comma there.
works for 1,000, 1,000,000, 1,000,000,000 and so on