Skip to content

Instantly share code, notes, and snippets.

@tdshipley
Created September 1, 2015 19:58
Show Gist options
  • Save tdshipley/288160b4c8d0c5ab084e to your computer and use it in GitHub Desktop.
Save tdshipley/288160b4c8d0c5ab084e to your computer and use it in GitHub Desktop.
# Taken from http://stackoverflow.com/questions/3668345/calculate-percentage-in-ruby
class Numeric
def percent_of(n)
self.to_f / n.to_f * 100.0
end
end
1.percent_of 10 # => 10.0 (%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment