るりまサーチ

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

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. module >
  4. comparable >
  5. integer >

ライブラリ

クラス

キーワード

検索結果

<< 1 2 3 > >>

Float#round(ndigits = 0) -> Integer | Float (18316.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 (18316.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 (18279.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 (18255.0)

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

...ational(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...

Numeric#round -> Integer (18231.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 (18231.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...

Float#truncate(ndigits = 0) -> Integer | Float (15231.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...

Float#truncate -> Integer (15219.0)

小数点以下を切り捨てて値を整数に変換します。

...小数点以下を切り捨てて値を整数に変換します。


//emlist[例][ruby]{
2.8.truncate # => 2
(-2.8).truncate # => -2
//}

@see Numeric#round, Numeric#ceil, Numeric#floor...

BigDecimal.mode(s) -> Integer | nil (196.0)

BigDecimal の計算処理の制御方法を設定、確認します。

...を行う項目を BigDecimal::EXCEPTION_*、
BigDecimal::ROUND_MODE のいずれかで指定します。

@param v 引数 s が BigDecimal::ROUND_MODE の場合は
BigDecimal::ROUND_MODE 以外の BigDecimal::_ROUND* のいず
れかを指定します。指定した丸め...
...l'
flag = BigDecimal::ROUND_HALF_UP # デフォルト値
f = BigDecimal::mode(BigDecimal::ROUND_MODE,flag)
//}

の形式で指定します。
ここで、flag は以下(括弧内は対応するインスタンスメソッド)の一つを指定します。

* BigDecimal::ROUND_UP 全て切り上げ...
...ます。
* BigDecimal::ROUND_DOWN 全て切り捨てます(truncate)。
* BigDecimal::ROUND_HALF_UP 四捨五入します(デフォルト)。
* BigDecimal::ROUND_HALF_DOWN 五捨六入します。
* BigDecimal::ROUND_HALF_EVEN 四捨六入します。5の時は上位1桁が奇数の時の...

BigDecimal.mode(s, v) -> Integer | nil (196.0)

BigDecimal の計算処理の制御方法を設定、確認します。

...を行う項目を BigDecimal::EXCEPTION_*、
BigDecimal::ROUND_MODE のいずれかで指定します。

@param v 引数 s が BigDecimal::ROUND_MODE の場合は
BigDecimal::ROUND_MODE 以外の BigDecimal::_ROUND* のいず
れかを指定します。指定した丸め...
...l'
flag = BigDecimal::ROUND_HALF_UP # デフォルト値
f = BigDecimal::mode(BigDecimal::ROUND_MODE,flag)
//}

の形式で指定します。
ここで、flag は以下(括弧内は対応するインスタンスメソッド)の一つを指定します。

* BigDecimal::ROUND_UP 全て切り上げ...
...ます。
* BigDecimal::ROUND_DOWN 全て切り捨てます(truncate)。
* BigDecimal::ROUND_HALF_UP 四捨五入します(デフォルト)。
* BigDecimal::ROUND_HALF_DOWN 五捨六入します。
* BigDecimal::ROUND_HALF_EVEN 四捨六入します。5の時は上位1桁が奇数の時の...

絞り込み条件を変える

Float#to_i -> Integer (131.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...

BigDecimal.limit(n = nil) -> Integer (112.0)

生成されるBigDecimalオブジェクトの最大桁数をn桁に制限します。 n を指定しない、または n が nil の場合は、現状の最大桁数が返ります。

...の場合 BigDecimal.mode で指定された丸め処理が
実行されます。ただし、インスタンスメソッド (BigDecimal#truncate /
BigDecimal#round / BigDecimal#ceil / BigDecimal#floor /
BigDecimal#add/ BigDecimal#sub / BigDecimal#mult /
BigDecimal#div) の桁数制限は limit よ...
<< 1 2 3 > >>