Class: Numeric

Inherits:
Object show all
Defined in:
opal/fron/core_ext/numeric.rb

Overview

Numeric

Instance Method Summary collapse

Instance Method Details

#clamp(min, max) ⇒ Numeric

Clamps itself between two values

Parameters:

  • min (Numeric)

    The minimum value

  • max (Numeric)

    The maximum value

Returns:


9
10
11
# File 'opal/fron/core_ext/numeric.rb', line 9

def clamp(min, max)
  [[self, max].min, min].max
end

#round(decimals = 0) ⇒ Float

Rounds itself to the given number of decimals

Parameters:

  • decimals (Numeric) (defaults to: 0)

    The number of decimals

Returns:

  • (Float)

    The rounded value


18
19
20
# File 'opal/fron/core_ext/numeric.rb', line 18

def round(decimals = 0)
  `#{self}.toFixed(#{decimals})`.to_f
end