number = 12345678
number.to_s.gsub(/\B(?=(...)*\b)/, ',')
# => "12,345,678"
This does not work if your number has a negative sign (-1234
), neither if it
has a decimal separator (1.234
). I said it was a quick way, not a good way
;).
number = 12345678
number.to_s.gsub(/\B(?=(...)*\b)/, ',')
# => "12,345,678"
This does not work if your number has a negative sign (-1234
), neither if it
has a decimal separator (1.234
). I said it was a quick way, not a good way
;).