Module: Darthjee::CoreExt::Numeric

Included in:
Numeric
Defined in:
lib/darthjee/core_ext/numeric.rb

Instance Method Summary collapse

Instance Method Details

#percent_of(total) ⇒ ::Float

Returns the percentage over total

Examples:

10.percent_of(30) # returns 33.33333333333333

Parameters:

  • total (::Numeric)

    total over which to calculate the percentage

Returns:

  • (::Float)


16
17
18
19
# File 'lib/darthjee/core_ext/numeric.rb', line 16

def percent_of(total)
  return Float::INFINITY if total&.zero?
  (to_f / total.to_f) * 100.0
end