Rounding a float to the nearest integer in ruby -
if have float of 49.967 , .to_i chop down 49 use of disk space analysis .967 on 900mb of space wont accounted in displays.
is there function round numbers nearest integer or have define self this:
class float def to_nearest_i (self+0.5).to_i end end so do:
>> 5.44.to_nearest_i => 5 >> 5.54.to_nearest_i => 6
try float.round.
irb(main):001:0> 5.44.round => 5 irb(main):002:0> 5.54.round => 6
Comments
Post a Comment