Rounding a float to the nearest integer in ruby

后端 未结 1 1940
余生分开走
余生分开走 2021-02-11 11:57

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:33

    Try Float.round.

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

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