4. String

4.11 String to number using to_i

“12” is not an integer. If we try to add a number to string then we will get an error.

If we want to convert string into an integer then we need to use to_i method. to_i is a short form of “to integer”.

Let’s fix the last example. Execute the code now.