Logo

Programming-Idioms

History of Idiom 22 > diff from v51 to v52

Edit summary for version 52 by programming-idioms.org:
[Ruby] +DemoURL

Version 51

2016-11-11, 16:17:08

Version 52

2016-11-13, 22:34:44

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration
Extra Keywords
int base
Extra Keywords
int base
Code
i = s.to_i
Code
i = s.to_i
Comments bubble
to_i returns 0 if s is not a valid number.
Comments bubble
to_i returns 0 if s is not a valid number.
Doc URL
http://ruby-doc.org/core-2.3.0/String.html#to_i-method
Doc URL
http://ruby-doc.org/core-2.3.0/String.html#to_i-method
Demo URL
https://repl.it/EWrW/0