るりまサーチ

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

別のキーワード

  1. openssl integer
  2. asn1 integer
  3. _builtin integer
  4. integer upto
  5. integer chr

ライブラリ

クラス

キーワード

検索結果

Float#round(ndigits = 0) -> Integer | Float (18318.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 (18318.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 (18280.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...

Numeric (118.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...数値を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッ...
...o - - -
* | - - o o o o o
**
| - - o o o o o
+ | - - o...
...- - - o
remainder | o - - o - - -
round
| o o - - o o -
singleton_method_added | o - -...
...& | - o - - -
* | - o o o o
**
| - o o o o
+ | - o o o o...
...angular | o - - - o
remainder | o o - - -
round
| o o o o -
singleton_method_added | o - - - -...

bigdecimal (42.0)

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

...math"
a = BigMath.E(10)
p c = "0.123456789" * a # => "0.1234567890.123456789"
//}

これは、String#* の内部で、BigDecimal が暗黙的に Integer に変換された結果です。

===[a:internal_structure] 内部構造

BigDecimal内部で浮動小数点は構造体(Real)で表現されま...
...下の構造体要素 frac) で管理されます。
概念的には、以下のようになります。

<浮動小数点数> = 0.xxxxxxxxx * BASE ** n

ここで、x は仮数部を表す数字、BASE は基数 (10 進表現なら 10)、
n は指数部を表す整数値です。BASEが大きい...
...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
//}

====...

絞り込み条件を変える