Method: Float#percent
- Defined in:
- lib/epitools/core_ext/numbers.rb
#percent(decimals = 0) ⇒ Object
Convert the float to a rounded percentage string (eg: “42%”). Its argument lets you specify how many decimals to display
eg:
> 0.32786243.percent # => "33%"
> 0.32786243.percent(2) # => "32.79%"
387 388 389 |
# File 'lib/epitools/core_ext/numbers.rb', line 387 def percent(decimals=0) "%0.#{decimals}f%" % (self * 100) end |