Skip to content

Instantly share code, notes, and snippets.

@mattmawhinney
Created June 19, 2013 19:03
Show Gist options
  • Save mattmawhinney/5816991 to your computer and use it in GitHub Desktop.
Save mattmawhinney/5816991 to your computer and use it in GitHub Desktop.
A method to insert commas into numbers that are 4 digits or longer. An exercise in using regular expressions.
def separate_comma(number)
number.to_s.gsub(/(\d)(?=(\d{3})+$)/, '\1,')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment