Turn numbers into strings with thousands' separators
1 2 class Numeric 3 def commify(dec='.', sep=',') 4 num = to_s.sub(/\./, dec) 5 dec = Regexp.escape dec 6 num.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*#{dec})/, "\\1#{sep}").reverse 7 end 8 end
So, you get:
1 2 1233232423424.23423.commify # => "1,233,232,423,424.23"