るりまサーチ

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

別のキーワード

  1. _builtin to_s
  2. openssl to_der
  3. openssl to_s
  4. _builtin to_a
  5. openssl to_pem

ライブラリ

クラス

キーワード

検索結果

Rational#to_f -> Float (27198.0)

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

...{
Rational
(2).to_f # => 2.0
Rational
(9, 4).to_f # => 2.25
Rational
(-3, 4).to_f # => -0.75
Rational
(20, 3).to_f # => 6.666666666666667
Rational
(1, 10**1000).to_f # => 0.0
Rational
(-1, 10**1000).to_f # => -0.0
Rational
(10**1000).to_f # => Infinity
Rational
(...
...-10**1000).to_f # => -Infinity
//}...

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

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

...[ruby]{
Rational
(3).floor # => 3
Rational
(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...
... Rational を返します。

//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#tr...

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

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

...//emlist[例][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...

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

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

...by]{
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]{
Rational
('-...
...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...

Rational#ceil(precision = 0) -> Integer | Rational (9174.0)

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

...//emlist[例][ruby]{
Rational
(3).ceil # => 3
Rational
(2, 3).ceil # => 1
Rational
(-3, 2).ceil # => -1
//}

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

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

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

絞り込み条件を変える

Rational#to_i -> Integer (9080.0)

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

...by]{
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]{
Rational
('-...
...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...

Time#subsec -> Integer | Rational (120.0)

時刻を表す分数を返します。

...時刻を表す分数を返します。

Rational
を返す場合があります。

//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5,6)
p "%10.9f" % t.to_f # => "946749845.000005960"
p t.subsec #=> (3/500000)
//}

to_f
の値と subsec の値の下のほうの桁の値は異なる場...

Numeric#coerce(other) -> [Numeric] (43.0)

自身と other が同じクラスになるよう、自身か other を変換し [other, self] という配列にして返します。

...下は Rational の coerce のソースです。other が自身の知らない数値クラスであった場合、
super を呼んでいることに注意して下さい。


//emlist[例][ruby]{
# lib/rational.rb より

def coerce(other)
if other.kind_of?(Float)
return other, self.to_f
els...
...turn Rational.new!(other, 1), self
else
super
end
end
//}

数値クラスの算術演算子は通常自分と演算できないクラスをオペランドとして受け
取ると coerce を使って自分とオペランドを変換した上で演算を行います。
以下は Rational...
...、引数の coerce により自身を変換してから
+ 演算子を呼んでいます。

//emlist[例][ruby]{
# lib/rational.rb より

def + (a)
if a.kind_of?(Rational)
# 長いので省略
elsif a.kind_of?(Integer)
# 長いので省略
elsif a.kind_of?(Float)
Float(self) + a...