Rounding a float to the nearest integer in ruby

后端 未结 1 1040
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-11 11:59

If i have a float of 49.967 and I do .to_i it will chop it down to 49 which for my use of disk space analysis .967 is over 900mb of space that wont be accounted for in the displ

1条回答
  •  佛祖请我去吃肉
    2021-02-11 12:24

    Try Float.round.

    irb(main):001:0> 5.44.round
    => 5
    irb(main):002:0> 5.54.round
    => 6
    

    0 讨论(0)
提交回复
热议问题