るりまサーチ

最速Rubyリファレンスマニュアル検索!
38件ヒット [1-38件を表示] (0.017秒)
トップページ > クエリ:Math[x] > クエリ:round[x]

別のキーワード

  1. math log
  2. math sqrt
  3. _builtin math
  4. bigdecimal/math sin
  5. bigdecimal/math e

ライブラリ

クラス

キーワード

検索結果

Float#round(ndigits = 0) -> Integer | Float (18216.0)

自身ともっとも近い整数もしくは実数を返します。

...]{
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 Float#ceil, Float#floor, Float#truncate...

Float#round(ndigits = 0, half: :up) -> Integer | Float (18216.0)

自身ともっとも近い整数もしくは実数を返します。

...]{
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 Float#ceil, Float#floor, Float#truncate...

Float#round(ndigits = 0) -> Integer | Float (18179.0)

自身ともっとも近い整数もしくは実数を返します。

...]{
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
//}

@see Float#ceil, Float#floor, Float#truncate...

NEWS for Ruby 2.4.0 (36.0)

NEWS for Ruby 2.4.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...追加 9969

* Float
* Float#ceil, Float#floor, Float#truncate は
Float#roundと同じように省略可能な桁を指定する引数を受け付けるようになりました。12245
* Float#round は half というキーワード引数を受け付けるようになりました。...
...ncate は
Integer#round と同じように省略可能な桁を指定する引数を受け付けるようになりました 12245
* Integer#digits を追加。 12447
位置記法のために各桁を展開するためのメソッドです。
* Integer#round は half というキ...
...=== 実装の改善

* いくつかの条件で [x,y].max と [x,y].min が一時的な配列を生成しないよう最適化されました。
Math
.max(x, y) と書くようなほとんどのカジュアルで実際にありそうなユースケースで効果があります。
具体的...

bigdecimal (36.0)

bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。

...ーにはなりません。
"10XX"なら 10、"XXXX"は 0 と扱われます。

//emlist[][ruby]{
require "bigdecimal"
require "bigdecimal/math"

a = BigMath.E(20)
c = a * "0.123456789123456789123456789" # 文字列を BigDecimal に変換してから計算
//}

無限大や非数を表す文字...
...丈夫です。
ただ、文字列が左にあると計算はできません。

//emlist[][ruby]{
require "bigdecimal"
require "bigdecimal/math"
a = BigMath.E(10)
p c = "0.123456789" * a # => "0.1234567890.123456789"
//}

これは、String#* の内部で、BigDecimal が暗黙的に Integer に...
...2.0 / 3.0
# => 0.6666666666 67e0
//}

: truncate, round, ceil, floor

これらのメソッドは小数点からの相対位置を指定して桁数を決定します。

//emlist[][ruby]{
require "bigdecimal"
p BigDecimal("6.66666666666666").round(12).to_s(10)
# => 0.6666666666 667e1
//}

====...

絞り込み条件を変える