Created
August 18, 2013 06:42
-
-
Save thatandyrose/6260249 to your computer and use it in GitHub Desktop.
A little percentage helper for all ruby numbers!
This file contains hidden or 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
class Numeric | |
#usage: | |
#9.53.as_percent(11,2) => 86.64 | |
#9.53.as_percent(11,1) => 86.6 | |
#9.53.as_percent(11) => 87 | |
def as_percent(max,precision = 0) | |
((self.to_f/max)*100).round(precision) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment