107件ヒット
[1-100件を表示]
(0.112秒)
ライブラリ
- ビルトイン (107)
キーワード
-
bit
_ length (6) - floor (11)
- round (46)
- truncate (33)
検索結果
先頭5件
-
Numeric
# ceil -> Integer (21126.0) -
自身と等しいかより大きな整数のうち最小のものを返します。
...自身と等しいかより大きな整数のうち最小のものを返します。
//emlist[例][ruby]{
1.ceil #=> 1
1.2.ceil #=> 2
(-1.2).ceil #=> -1
(-1.5).ceil #=> -1
//}
@see Numeric#floor, Numeric#round, Numeric#truncate... -
Float
# round(ndigits = 0) -> Integer | Float (6107.0) -
自身ともっとも近い整数もしくは実数を返します。
...で四捨五入されます。
ndigitsが0より小さいならば、小数点以上の指定された位で四捨五入されます。
@return 指定された引数に応じて、整数もしくは実数を返します。
ndigitsが0ならば、整数を返します。
ndigits......][ruby]{
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......サポートされている値は以下の通りです。
* :up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に丸められます。
* :down: 0に近い方に丸められます。
@return 指定された引数に応じて、整数もしくは実数を......(-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 (6107.0) -
自身ともっとも近い整数もしくは実数を返します。
...サポートされている値は以下の通りです。
* :up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に丸められます。
* :down: 0に近い方に丸められます。
@return 指定された引数に応じて、整数もしくは実数を......][ruby]{
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... -
Numeric
# round -> Integer (6107.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#floor, Numeric#truncate... -
Numeric
# truncate -> Integer (6107.0) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
...0 から 自身までの整数で、自身にもっとも近い整数を返します。
//emlist[例][ruby]{
1.truncate #=> 1
1.2.truncate #=> 1
(-1.2).truncate #=> -1
(-1.5).truncate #=> -1
//}
@see Numeric#ceil, Numeric#floor, Numeric#round... -
Rational
# round(precision = 0) -> Integer | Rational (6107.0) -
自身ともっとも近い整数を返します。
...ist[例][ruby]{
Rational(3).round # => 3
Rational(2, 3).round # => 1
Rational(-3, 2).round # => -2
//}
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
//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#floor, Rational#truncate... -
Time
# round(ndigits=0) -> Time (6107.0) -
十進小数点数で指定した桁数の精度で丸めをし、 その Time オブジェクトを返します。 (デフォルトは0、つまり小数点の所で丸めます)。
...)
//emlist[][ruby]{
require 'time'
t = Time.utc(1999,12,31, 23,59,59)
p((t + 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))......000-01-01T00:00:00.000Z"
p((t + 1.49).round.iso8601(3)) # => "2000-01-01T00: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... -
Float
# truncate -> Integer (3107.0) -
小数点以下を切り捨てて値を整数に変換します。
...小数点以下を切り捨てて値を整数に変換します。
//emlist[例][ruby]{
2.8.truncate # => 2
(-2.8).truncate # => -2
//}
@see Numeric#round, Numeric#ceil, Numeric#floor... -
Float
# truncate(ndigits = 0) -> Integer | Float (3107.0) -
小数点以下を切り捨てて値を整数に変換します。
...す。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[例][ruby]{
2.8.truncate # => 2
(-2.8).truncate # => -2
1.234567.truncate(2) # => 1.23
34567.89.truncate(-2) # => 34500
//}
@see Numeric#round, Numeric#ceil, Numeric#floor... -
Rational
# truncate(precision = 0) -> Rational | Integer (3107.0) -
小数点以下を切り捨てて値を整数に変換します。
...t[例][ruby]{
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-31, 2).to_i # => -15
//}
precision を指定した場合は指定した桁数で切り捨てた整数か
Rational を返します。
//emlist[例][ruby]{
Ra......tional('-123.456').truncate(+1) # => (-617/5)
Rational('-123.456').truncate(+1).to_f # => -123.4
Rational('-123.456').truncate(0) # => -123
Rational('-123.456').truncate(-1) # => -120
//}
@see Rational#ceil, Rational#floor... -
Bignum
# bit _ length -> Integer (3007.0) -
self を表すのに必要なビット数を返します。
...ま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果
(-2**10000-1).bit_length # => 10001
(-2**10000).bit_length # => 10000
(-2**10000+1).bit......(-2**1000+1).bit_length # => 1000
(2**1000-1).bit_length # => 1000
(2**1000).bit_length # => 1001
(2**1000+1).bit_length # => 1001
(2**10000-1).bit_length # => 10000
(2**10000).bit_length # => 10001
(2**10000+1).bit_length # => 10001
@see Fixnum#bit_length... -
Fixnum
# bit _ length -> Integer (3007.0) -
self を表すのに必要なビット数を返します。
...ま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果
(-2**12-1).bit_length # => 13
(-2**12).bit_length # => 12
(-2**12+1).bit_length......h # => 0
0.bit_length # => 0
1.bit_length # => 1
0xff.bit_length # => 8
0x100.bit_length # => 9
(2**12-1).bit_length # => 12
(2**12).bit_length # => 13
(2**12+1).bit_length # => 13
@see Bignum#bit_length... -
Numeric
# floor -> Integer (3007.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...自身と等しいかより小さな整数のうち最大のものを返します。
//emlist[例][ruby]{
1.floor #=> 1
1.2.floor #=> 1
(-1.2).floor #=> -2
(-1.5).floor #=> -2
//}
@see Numeric#ceil, Numeric#round, Numeric#truncate... -
Numeric
# floor(ndigits = 0) -> Integer (3007.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[例][ruby]{
1.floor #=> 1
1.2.floor #=> 1
(-1.2).floor #=> -2
(-1.5).floor #=> -2
//}
@see Numeric#ceil, Numeric#round, Numeric#truncate
@see Integer#floor...