From: Warren Brown Date: 2003-08-06T01:07:01+09:00 Subject: Re: format number with comma separators? >> Yet another regex solution: >> >> % ruby -e 'puts "456778904".gsub(/(.)(?=.{3}+$)/, %q(\1,))' >> 456,778,904 >> >> -- fxn >> >> .gsub(/(\d)(?=\d{3}+$)/, '\1,') > > That spurious line at the end uses a regex that works for negative > numbers as well. If you want to allow a decimal point: irb(main):001:0> puts "-123456789.01".gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,') -123,456,789.01 - Warren Brown