Skip to content

Instantly share code, notes, and snippets.

@thatandyrose
Created August 18, 2013 06:42
Show Gist options
  • Save thatandyrose/6260249 to your computer and use it in GitHub Desktop.
Save thatandyrose/6260249 to your computer and use it in GitHub Desktop.
A little percentage helper for all ruby numbers!
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