るりまサーチ

最速Rubyリファレンスマニュアル検索!
240件ヒット [1-100件を表示] (0.117秒)

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

キーワード

検索結果

<< 1 2 3 > >>

String#to_f -> Float (21228.0)

文字列を 10 進数表現と解釈して、浮動小数点数 Float に変換します。

...ist[][ruby]{
p "-10".to_f # => -10.0
p "10e2".to_f # => 1000.0
p "1e-2".to_f # => 0.01
p ".1".to_f # => 0.1

p "1_0_0".to_f # => 100.0 # 数値リテラルと同じように区切りに _ を使える
p " \n10".to_f # => 10.0 # 先頭の空白・改行は無視される
p "7xa.5".to_f # =>...
...0 を返します。
変換対象が空文字列のケースでも、0.0 を返します。

//emlist[][ruby]{
p "".to_f # => 0.0
p "nan".to_f # => 0.0
p "INF".to_f # => 0.0
p "-Inf".to_f # => 0.0
//}

変換後の Float が有限の値を取れないときは、Float::INFINITY を用い...
...t[][ruby]{
#!ruby -W2

p ("10" * 1000).to_f # => Infinity
# warning: Float 10101010101010101010... out of range
//}

なお、このメソッドとは逆に、数値を文字列に変換するには
Kernel.#sprintf, String#%, Integer#to_s
を使用します。

@
see String#hex, String#oct, String#...

Rational#to_f -> Float (21168.0)

自身の値を最も良く表現する Float に変換します。

...

@
return Float を返します。

//emlist[例][ruby]{
R
ational(2).to_f # => 2.0
R
ational(9, 4).to_f # => 2.25
R
ational(-3, 4).to_f # => -0.75
R
ational(20, 3).to_f # => 6.666666666666667
R
ational(1, 10**1000).to_f # => 0.0
R
ational(-1, 10**1000).to_f # =>...
...-0.0
R
ational(10**1000).to_f # => Infinity
R
ational(-10**1000).to_f # => -Infinity
//}...

BigDecimal#floor -> Integer (6243.0)

self 以下の最大整数を返します。

...self 以下の最大整数を返します。

@
param n 小数点以下の桁数を整数で指定します。

//emlist[][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").floor # => 1
BigDecimal("-1.23456").floor # => -2
//}

以下のように引数 n を与えることもできます。
n >=...
...にします)。
n が負のときは小数点以上 n 桁目を操作します
(小数点位置から左に少なくとも n 個の 0 が並びます)。

//emlist[][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").floor(4).to_f # => 1.2345
BigDecimal("15.23456").floor(-1).to_f # => 10.0
//}...

BigDecimal#round -> Integer (6179.0)

クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した BigDecimal::ROUND_MODE に従って丸め操作を実行します。

...クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した
BigDecimal::ROUND_MODE に従って丸め操作を実行します。

@
param n 小数点以下の桁数を整数で指定します。

@
param b 丸め処理の方式として、BigDecimal.mode の第 1 引数と同...
...gDecimal::ROUND_MODE,flag) で何も指定せず、
かつ、引数を指定しない場合は
「小数点以下第一位の数を四捨五入して整数(BigDecimal 値)」にします。

//emlist[][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round # => 1
BigDecimal("-1.23456").round # =...
...][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round(4).to_f # => 1.2346
BigDecimal("15.23456").round(-1).to_f # => 20.0
//}

2番目の引数を指定すると、BigDecimal.mode の指定を無視して、指定さ
れた方法で丸め操作を実行します。

//emlist[][ruby]{
r
equire...

BigDecimal#round(n) -> BigDecimal (6179.0)

クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した BigDecimal::ROUND_MODE に従って丸め操作を実行します。

...クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した
BigDecimal::ROUND_MODE に従って丸め操作を実行します。

@
param n 小数点以下の桁数を整数で指定します。

@
param b 丸め処理の方式として、BigDecimal.mode の第 1 引数と同...
...gDecimal::ROUND_MODE,flag) で何も指定せず、
かつ、引数を指定しない場合は
「小数点以下第一位の数を四捨五入して整数(BigDecimal 値)」にします。

//emlist[][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round # => 1
BigDecimal("-1.23456").round # =...
...][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round(4).to_f # => 1.2346
BigDecimal("15.23456").round(-1).to_f # => 20.0
//}

2番目の引数を指定すると、BigDecimal.mode の指定を無視して、指定さ
れた方法で丸め操作を実行します。

//emlist[][ruby]{
r
equire...

絞り込み条件を変える

BigDecimal#round(n, b) -> BigDecimal (6179.0)

クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した BigDecimal::ROUND_MODE に従って丸め操作を実行します。

...クラスメソッド BigDecimal.mode(BigDecimal::ROUND_MODE,flag) で指定した
BigDecimal::ROUND_MODE に従って丸め操作を実行します。

@
param n 小数点以下の桁数を整数で指定します。

@
param b 丸め処理の方式として、BigDecimal.mode の第 1 引数と同...
...gDecimal::ROUND_MODE,flag) で何も指定せず、
かつ、引数を指定しない場合は
「小数点以下第一位の数を四捨五入して整数(BigDecimal 値)」にします。

//emlist[][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round # => 1
BigDecimal("-1.23456").round # =...
...][ruby]{
r
equire "bigdecimal"
BigDecimal("1.23456").round(4).to_f # => 1.2346
BigDecimal("15.23456").round(-1).to_f # => 20.0
//}

2番目の引数を指定すると、BigDecimal.mode の指定を無視して、指定さ
れた方法で丸め操作を実行します。

//emlist[][ruby]{
r
equire...

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

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

...のものを返します。

@
param precision 計算結果の精度

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

//emlist[例][ruby]{
R
ational(3).floor # => 3
R
ational(2, 3).floor # => 0
R
ational(-3, 2).floor # => -2
//}

R
ational#to_i とは違う...
...[例][ruby]{
R
ational(+7, 4).to_i # => 1
R
ational(+7, 4).floor # => 1
R
ational(-7, 4).to_i # => -1
R
ational(-7, 4).floor # => -2
//}

precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。

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

@
see Rational#ceil, Rational#round, Rational#truncate...

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

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

...切り上げされます。

@
param precision 計算結果の精度

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

//emlist[例][ruby]{
R
ational(3).round # => 3
R
ational(2, 3).round # => 1
R
ational(-3, 2).round # => -2
//}

precision を指定した場...
... Rational を返します。

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

@
see Rat...
...ional#ceil, Rational#floor, Rational#truncate...

Rational#truncate(precision = 0) -> Rational | Integer (6149.0)

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

...換します。

@
param precision 計算結果の精度

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

//emlist[例][ruby]{
R
ational(2, 3).to_i # => 0
R
ational(3).to_i # => 3
R
ational(300.6).to_i # => 300
R
ational(98, 71).to_i # => 1
R
ational(-31, 2...
...//}

precision を指定した場合は指定した桁数で切り捨てた整数か
R
ational を返します。

//emlist[例][ruby]{
R
ational('-123.456').truncate(+1) # => (-617/5)
R
ational('-123.456').truncate(+1).to_f # => -123.4
R
ational('-123.456').truncate(0) # => -123
R
ational...
...('-123.456').truncate(-1) # => -120
//}

@
see Rational#ceil, Rational#floor...
<< 1 2 3 > >>