Quick way to format numbers in Ruby

number = 12345678
number.to_s.gsub(/\B(?=(...)*\b)/, ',')

# => "12,345,678"

This does not work if your numner 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 ;).