Ruby 2.6.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Integerクラス > round

instance method Integer#round

round(ndigits = 0, half: :up) -> Integer[permalink][rdoc]

self ともっとも近い整数を返します。

[PARAM] ndigits:
10進数での小数点以下の有効桁数を整数で指定します。負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
[PARAM] half:
ちょうど半分の値の丸め方を指定します。サポートされている値は以下の通りです。

1.round         # => 1
1.round(2)      # => 1
15.round(-1)    # =>  20
(-15).round(-1) # => -20

25.round(-1, half: :up)      # => 30
25.round(-1, half: :down)    # => 20
25.round(-1, half: :even)    # => 20
35.round(-1, half: :up)      # => 40
35.round(-1, half: :down)    # => 30
35.round(-1, half: :even)    # => 40
(-25).round(-1, half: :up)   # => -30
(-25).round(-1, half: :down) # => -20
(-25).round(-1, half: :even) # => -20

[SEE_ALSO] Numeric#round