Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/classes/tools.rb

Instance Method Summary collapse

Instance Method Details

#roundoff(d = 0) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/classes/tools.rb', line 18

def roundoff(d=0)
  x = 10**d
  if self < 0
    (self * x - 0.5).ceil.quo(x)
  else
    (self * x + 0.5).floor.quo(x)
  end
end