0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

to_iメソッド

Posted at

#to_iメソッド

文字列が持つメソッドです。文字列を数値に変換してくれます。
ちなみに、 to_iのiの意味は「integer(整数)」です。
以下の例を見てください。

【例】irb
# 文字列30にto_iメソッドをつけて実行
irb(main):001:0> "30".to_i
=> 30

もし数字以外の文字列だった場合は、すべて数値0に変換されます。

#irbで以下のコードを実行しましょう

to_iメソッドを試してみましょう。

irb
# to_iで文字列を数値に変換
irb(main):001:0> "100".to_i + 400
=> 500

#まとめ

to_iメソッドとは、文字列を数値に変換するメソッド。

#####以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?