Skip to content

Instantly share code, notes, and snippets.

@cgallagher
Created November 4, 2009 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgallagher/226171 to your computer and use it in GitHub Desktop.
Save cgallagher/226171 to your computer and use it in GitHub Desktop.
Takes a flat number and uses a regex to format the commas
def self.formatViews(number)
number = number.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
number
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment