Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# 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