るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.027秒)
トップページ > クラス:String[x] > クエリ:to_f[x] > 種類:インスタンスメソッド[x]

別のキーワード

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

ライブラリ

キーワード

検索結果

String#to_f -> Float (18175.0)

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

...by]{
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 # => 7.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 を用います。...
...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#to_i,
Kernel.#...

String#hex -> Integer (8.0)

文字列に 16 進数で数値が表現されていると解釈して整数に変換します。 接頭辞 "0x", "0X" とアンダースコアは無視されます。 文字列が [_0-9a-fA-F] 以外の文字を含むときはその文字以降を無視します。

...# => 0
p "10z".hex # => 16
p "1_0".hex # => 16

p "".hex # => 0
//}

@see String#oct, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float

このメソッドの逆に数値を文字列に変換するには
Kernel.#sprintf, String#%,
Integer#to_s
などを使ってください。...

String#oct -> Integer (8.0)

文字列を 8 進文字列であると解釈して、整数に変換します。

...{
p "-010".oct # => -8
p "-0x10".oct # => -16
p "-0b10".oct # => -2

p "1_0_1x".oct # => 65
//}

@see String#hex, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float

逆に、数値を文字列に変換するにはKernel.#sprintf,
String
#%, Integer#to_s を使用します。...

String#to_i(base = 10) -> Integer (8.0)

文字列を 10 進数表現された整数であると解釈して、整数に変換します。

...する整数。0 か、2〜36 の整数。
@return 整数

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

String
#hex, String#oct, String#to_f,
Kernel.#Integer, Kernel.#Float
も参照してください。...