Skip to content

Instantly share code, notes, and snippets.

@mehagel
Created May 6, 2013 21:20
Show Gist options
  • Save mehagel/5528297 to your computer and use it in GitHub Desktop.
Save mehagel/5528297 to your computer and use it in GitHub Desktop.
def separate_comma(number)
if number < 1000
puts number
end
begin
parts = number.to_s.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
parts.join separator
rescue
return number
end
end
separate_comma(3456789)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment