round(ndigits = 0) -> Integer | Float[permalink][rdoc]round(ndigits = 0, half: :up) -> Integer | Float自身ともっとも近い整数もしくは実数を返します。
中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。いわゆる四捨五入ですが、偶数丸めではありません。
例
1.0.round      # => 1
1.2.round      # => 1
(-1.2).round   # => -1
(-1.5).round   # => -2
t = Math::PI # => 3.141592653589793
t.round(3)   # => 3.142
t.round(0)   # => 3
t.round(1)   # => 3.1
t = t**10      # => 93648.04747608298
t.round(-0)    # => 93648
t.round(-1)    # => 93650
t.round(-2)    # => 93600
t.round(-3)    # => 94000
t.round(-100)  # => 0
2.5.round(half: :up)   # => 3
2.5.round(half: :even) # => 2
2.5.round(half: :down) # => 2
3.5.round(half: :up)   # => 4
3.5.round(half: :even) # => 4
3.5.round(half: :down) # => 3
[SEE_ALSO] Float#ceil, Float#floor, Float#truncate