I want to convert 2333444 to 2,333,444, but I'm not clear on how to have the expression work its way from the right to the left as opposed to the other way around. I'm writing Perl, but any regEx syntax is fine, I'll convert it if you are more comfortable with java or javascript.
s/(?<=\d)(?=(\d\d\d)+(?!\d))/,/g
Check out Number::Format. This module provides a wide variety of number formatting solutions. e.g. for what you require
format_number(1234567.89, 2)
yields '1,234,567.89'
Don't forget that what you're trying to do is locale-specific, and this module will handle that for you. A simple regexp solution won't do that on it's own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With