るりまサーチ

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

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

クラス

キーワード

検索結果

<< 1 2 > >>

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

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

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

中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。
いわゆる四捨五入ですが、偶数丸めではありません。

@param ndigits 丸める位を指定します。
ndigitsが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 (18330.0)

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

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

中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。
いわゆる四捨五入ですが、偶数丸めではありません。

@param ndigits 丸める位を指定します。
ndigitsが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...

Time#round(ndigits=0) -> Time (18329.0)

十進小数点数で指定した桁数の精度で丸めをし、 その Time オブジェクトを返します。 (デフォルトは0、つまり小数点の所で丸めます)。

...4).round.iso8601(3)) # => "1999-12-31T23:59:59.000Z"
p((t + 0.49).round.iso8601(3)) # => "1999-12-31T23:59:59.000Z"
p((t + 0.5).round.iso8601(3)) # => "2000-01-01T00:00:00.000Z"
p((t + 1.4).round.iso8601(3)) # => "2000-01-01T00:00:00.000Z"
p((t + 1.49).round.iso8601(3)) # => "2000-01-01...
...T00:00:00.000Z"
p((t + 1.5).round.iso8601(3)) # => "2000-01-01T00:00:01.000Z"

t = Time.utc(1999,12,31, 23,59,59)
p (t + 0.123456789).round(4).iso8601(6) # => "1999-12-31T23:59:59.123500Z"
//}...
...T00:00:00.000Z"
p((t + 1.5).round.iso8601(3)) # => "2000-01-01T00:00:01.000Z"

t = Time.utc(1999,12,31, 23,59,59)
p (t + 0.123456789).round(4).iso8601(6) # => "1999-12-31T23:59:59.123500Z"
//}

@see Time#ceil, Time#floor...

Integer#round(ndigits = 0, half: :up) -> Integer (18311.0)

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

...]{
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, ha...
...lf: :even) # => 40
(-25).round(-1, half: :up) # => -30
(-25).round(-1, half: :down) # => -20
(-25).round(-1, half: :even) # => -20
//}

@see Numeric#round...

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

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

...{
1.round # => 1
1.round(2) # => 1.0
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, h...
...alf: :even) # => 40
(-25).round(-1, half: :up) # => -30
(-25).round(-1, half: :down) # => -20
(-25).round(-1, half: :even) # => -20
//}

@see Numeric#round...

絞り込み条件を変える

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

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

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

中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。
いわゆる四捨五入ですが、偶数丸めではありません。

@param ndigits 丸める位を指定します。
ndigitsが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...

Rational#round(precision = 0) -> Integer | Rational (18287.0)

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

....5, -0.5 はそれぞれ 1,-1 に切り上げされます。

@param precision 計算結果の精度

@raise TypeError precision に整数以外のものを指定すると発生します。

//emlist[例][ruby]{
Rational(3).round # => 3
Rational(2, 3).round # => 1
Rational(-3, 2).round # => -2...
...す。

//emlist[例][ruby]{
Rational('-123.456').round(+1) # => (-247/2)
Rational('-123.456').round(+1).to_f # => -123.5
Rational('-123.456').round(0) # => -123
Rational('-123.456').round(-1) # => -120
Rational('-123.456').round(-2) # => -100
//}

@see Rational#ceil, Rational#f...

Numeric#round -> Integer (18245.0)

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

...返します。

中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。いわゆる四捨五入ですが、偶数丸めではありません。

//emlist[例][ruby]{
1.round #=> 1
1.2.round #=> 1
(-1.2).round #=> -1
(-1.5).round #=> -2
//}

@see Numeric#ceil, Numeric...

Float::ROUNDS -> Integer (6202.0)

この定数は Ruby 2.7 から deprecated です。使わないでください。

...この定数は Ruby 2.7 から deprecated です。使わないでください。


丸めモード (-1: 不定、0: 0.0 の方向に丸め、1: 四捨五入、2:正の無限
大の方向に丸め、3:負の無限大の方向に丸め)です。...

Numeric (2198.0)

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

...されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは、サブクラスで提供されているメソッド
(+, -, *, /, %) を利用して定義されるものがほとんど...
...を定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)だけを定義すれば、数値クラスのそのほかのメソッドが
適切に定義されることを意図して提供されています。

+@, -@ は単項演算子 +, - を表しメソッド定義などではこの記...
...95 (2014-05-08 revision 45877) [x86_64-linux]
Numeric Integer Fixnum Bignum Float Rational Complex
-
------------------------------------------------------------------------------------------
% | o -...
...198 (2017-09-14 revision 59899) [x86_64-darwin15]
Numeric Integer Float Rational Complex
-
-------------------------------------------------------------------------------
% | o o o - -...

絞り込み条件を変える

Time#ceil(ndigits=0) -> Time (252.0)

十進小数点数で指定した桁数の精度で切り上げをし、 その Time オブジェクトを返します。 (デフォルトは0、つまり小数点の所で切り上げます)。

...(10) # => "2010-03-30T05:43:25.0123456789Z"
t.ceil.iso8601(10) # => "2010-03-30T05:43:26.0000000000Z"
t.ceil(0).iso8601(10) # => "2010-03-30T05:43:26.0000000000Z"
t.ceil(1).iso8601(10) # => "2010-03-30T05:43:25.1000000000Z"
t.ceil(2).iso8601(10) # => "2010-03-30T05:43:25.0200000000Z"...
...2010-03-30T05:43:25.0130000000Z"
t.ceil(4).iso8601(10) # => "2010-03-30T05:43:25.0124000000Z"

t = Time.utc(1999,12,31, 23,59,59)
(t + 0.4).ceil.iso8601(3) # => "2000-01-01T00:00:00.000Z"
(t + 0.9).ceil.iso8601(3) # => "2000-01-01T00:00:00.000Z"
(t + 1.4).ceil.iso8601(3) # => "2000-01-01T0...
...0:00:01.000Z"
(t + 1.9).ceil.iso8601(3) # => "2000-01-01T00:00:01.000Z"

t = Time.utc(1999,12,31, 23,59,59)
(t + 0.123456789).ceil(4).iso8601(6) # => "1999-12-31T23:59:59.123500Z"
//}

@see Time#floor, Time#round...

Time#floor(ndigits=0) -> Time (252.0)

十進小数点数で指定した桁数の精度で切り捨てをし、 その Time オブジェクトを返します。 (デフォルトは0、つまり小数点の所で切り捨てます)。

...) # => "2010-03-30T05:43:25.1234567890Z"
t.floor.iso8601(10) # => "2010-03-30T05:43:25.0000000000Z"
t.floor(0).iso8601(10) # => "2010-03-30T05:43:25.0000000000Z"
t.floor(1).iso8601(10) # => "2010-03-30T05:43:25.1000000000Z"
t.floor(2).iso8601(10) # => "2010-03-30T05:43:25.1200000000...
...10-03-30T05:43:25.1230000000Z"
t.floor(4).iso8601(10) # => "2010-03-30T05:43:25.1234000000Z"

t = Time.utc(1999,12,31, 23,59,59)
(t + 0.4).floor.iso8601(3) # => "1999-12-31T23:59:59.000Z"
(t + 0.9).floor.iso8601(3) # => "1999-12-31T23:59:59.000Z"
(t + 1.4).floor.iso8601(3) # => "2000-01-01...
...T00:00:00.000Z"
(t + 1.9).floor.iso8601(3) # => "2000-01-01T00:00:00.000Z"

t = Time.utc(1999,12,31, 23,59,59)
(t + 0.123456789).floor(4).iso8601(6) # => "1999-12-31T23:59:59.123400Z"
//}

@see Time#ceil, Time#round...

Rational#floor(precision = 0) -> Integer | Rational (144.0)

自身と等しいかより小さな整数のうち最大のものを返します。

...l(2, 3).floor # => 0
Rational(-3, 2).floor # => -2
//}

Rational#to_i とは違う結果を返す事に注意してください。

//emlist[例][ruby]{
Rational(+7, 4).to_i # => 1
Rational(+7, 4).floor # => 1
Rational(-7, 4).to_i # => -1
Rational(-7, 4).floor # => -2
//}

precision を指定し...
...onal を返します。

//emlist[例][ruby]{
Rational('-123.456').floor(+1) # => (-247/2)
Rational('-123.456').floor(+1).to_f # => -123.5
Rational('-123.456').floor(0) # => -124
Rational('-123.456').floor(-1) # => -130
//}

@see Rational#ceil, Rational#round, Rational#truncate...
<< 1 2 > >>