Class: Float

Inherits:
Object show all
Defined in:
lib/epitools/core_ext/numbers.rb,
lib/epitools/core_ext/truthiness.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

'true' if the float is 0.0

Returns:

  • (Boolean)

73
# File 'lib/epitools/core_ext/truthiness.rb', line 73

def blank?; self == 0.0; end

#float?Boolean

Returns:

  • (Boolean)

75
# File 'lib/epitools/core_ext/truthiness.rb', line 75

def float?; true; end

#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%"

424
425
426
# File 'lib/epitools/core_ext/numbers.rb', line 424

def percent(decimals=0)
  "%0.#{decimals}f%%" % (self * 100)
end