Class: Float

Inherits:
Object show all
Defined in:
lib/motel/common.rb

Overview

We extend Float to provide floating point rounding mechanism

Instance Method Summary collapse

Instance Method Details

#round_to(precision) ⇒ Object

Round float to the specified precision


305
306
307
308
# File 'lib/motel/common.rb', line 305

def round_to(precision)
   return nil if precision < 0
   return (self * 10 ** precision).round.to_f / (10 ** precision)
end