Created
September 1, 2015 19:58
-
-
Save tdshipley/288160b4c8d0c5ab084e to your computer and use it in GitHub Desktop.
Example taken from http://stackoverflow.com/questions/3668345/calculate-percentage-in-ruby for percentages in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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