ライブラリ
- ビルトイン (240)
- bigdecimal (72)
クラス
キーワード
-
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 2
. 5 . 0 (8) -
NEWS for Ruby 2
. 7 . 0 (6) - Numeric (12)
-
ROUND
_ CEILING (12) - bigdecimal (12)
-
bit
_ length (18) - ceildiv (3)
- floor (42)
- limit (12)
- mode (24)
- round (51)
-
to
_ i (24) - truncate (36)
検索結果
先頭5件
-
Numeric (48.0)
-
数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。
...arg | o - o - o
bit_length | - o - - -
ceil | o o o o -
chr | - o - - -......= 丸めメソッドの動作一覧
Numeric#ceil, Numeric#floor, Numeric#round, Numeric#truncate
のふるまいの違いの表です。左の実数に対して各メソッドを呼ぶと表のような数を
返します。
| ceil floor round truncate
----......| -1 -2 -2 -1
=== 丸めメソッドの拡張例
切上げはceil, floor を使用して以下のように定義できます。
//emlist[例][ruby]{
if n > 0 then
n.ceil
else
n.floor
end
//}
また、任意桁の切上げ、切捨て、四捨五入を行うメ... -
BigDecimal
. mode(s) -> Integer | nil (12.0) -
BigDecimal の計算処理の制御方法を設定、確認します。
...六入します。5の時は上位1桁が奇数の時のみ繰り上げます(Banker's rounding)。
* BigDecimal::ROUND_CEILING 数値の大きい方に繰り上げます(ceil)。
* BigDecimal::ROUND_FLOOR 数値の小さい方に繰り下げます(floor)。
戻り値は指定後の flag の値......。 mode メソッドでは丸め操作の位置をユーザが指定することはできません。丸め操作と位置を自分で制御したい場合は BigDecimal::limit や truncate/round/ceil/floor、 add/sub/mult/div といったインスタンスメソッドを使用して下さい。... -
BigDecimal
. mode(s , v) -> Integer | nil (12.0) -
BigDecimal の計算処理の制御方法を設定、確認します。
...六入します。5の時は上位1桁が奇数の時のみ繰り上げます(Banker's rounding)。
* BigDecimal::ROUND_CEILING 数値の大きい方に繰り上げます(ceil)。
* BigDecimal::ROUND_FLOOR 数値の小さい方に繰り下げます(floor)。
戻り値は指定後の flag の値......。 mode メソッドでは丸め操作の位置をユーザが指定することはできません。丸め操作と位置を自分で制御したい場合は BigDecimal::limit や truncate/round/ceil/floor、 add/sub/mult/div といったインスタンスメソッドを使用して下さい。... -
NEWS for Ruby 2
. 4 . 0 (12.0) -
NEWS for Ruby 2.4.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...ttps://github.com/ruby/ruby/pull/1186
* Enumerator::Lazy#uniq を追加 11090
* File
* File.empty? を追加 9969
* Float
* Float#ceil, Float#floor, Float#truncate は
Float#roundと同じように省略可能な桁を指定する引数を受け付けるようになりまし......ansform_values Hash#transform_values! を追加 12512
* Integer
* Fixnum と Bignum は Integer に統合されました 12005
* Integer#ceil, Integer#floor, Integer#truncate は
Integer#round と同じように省略可能な桁を指定する引数を受け付けるようになり... -
BigDecimal
. limit(n = nil) -> Integer (6.0) -
生成されるBigDecimalオブジェクトの最大桁数をn桁に制限します。 n を指定しない、または n が nil の場合は、現状の最大桁数が返ります。
...指定された丸め処理が
実行されます。ただし、インスタンスメソッド (BigDecimal#truncate /
BigDecimal#round / BigDecimal#ceil / BigDecimal#floor /
BigDecimal#add/ BigDecimal#sub / BigDecimal#mult /
BigDecimal#div) の桁数制限は limit より優先されます。
//eml... -
Bignum
# bit _ length -> Integer (6.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... -
Fixnum
# bit _ length -> Integer (6.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... -
Float
# floor -> Integer (6.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...自身と等しいかより小さな整数のうち最大のものを返します。
//emlist[例][ruby]{
1.2.floor # => 1
2.0.floor # => 2
(-1.2).floor # => -2
(-2.0).floor # => -2
//}
@see Numeric#ceil, Numeric#round, Float#truncate... -
Float
# floor(ndigits = 0) -> Integer | Float (6.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...oor(-4) # => 30000
34567.89.floor(-3) # => 34000
34567.89.floor(-2) # => 34500
34567.89.floor(-1) # => 34560
34567.89.floor(0) # => 34567
34567.89.floor(1) # => 34567.8
34567.89.floor(2) # => 34567.89
34567.89.floor(3) # => 34567.89
//}
@see Numeric#ceil, Numeric#round, Float#truncate... -
Float
# round(ndigits = 0) -> Integer | Float (6.0) -
自身ともっとも近い整数もしくは実数を返します。
...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......d(-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 (6.0) -
自身ともっとも近い整数もしくは実数を返します。
...d(-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
# to _ i -> Integer (6.0) -
小数点以下を切り捨てて値を整数に変換します。
...小数点以下を切り捨てて値を整数に変換します。
//emlist[例][ruby]{
2.8.truncate # => 2
(-2.8).truncate # => -2
//}
@see Numeric#round, Numeric#ceil, Numeric#floor......す。
小数点位置から左に少なくとも 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...