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


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


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

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