Class: Float
- Defined in:
- lib/epitools/core_ext/numbers.rb,
lib/epitools/core_ext/truthiness.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
‘true’ if the float is 0.0.
- #float? ⇒ Boolean
-
#percent(decimals = 1) ⇒ Object
Convert the float to a rounded percentage string (eg: “42.5%”).
Instance Method Details
#blank? ⇒ Boolean
‘true’ if the float is 0.0
73 |
# File 'lib/epitools/core_ext/truthiness.rb', line 73 def blank?; self == 0.0; end |
#float? ⇒ Boolean
75 |
# File 'lib/epitools/core_ext/truthiness.rb', line 75 def float?; true; end |
#percent(decimals = 1) ⇒ Object
Convert the float to a rounded percentage string (eg: “42.5%”). Its argument lets you specify how many decimals to display
eg:
> 0.32786243.percent # => "33.8%"
> 0.32786243.percent(2) # => "32.79%"
463 464 465 |
# File 'lib/epitools/core_ext/numbers.rb', line 463 def percent(decimals=1) "%0.#{decimals}f%%" % (self * 100) end |