Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics Numbers Converting Strings to Numbers

Saadia Fattah
Saadia Fattah
1,939 Points

I tried both of these methods for the integer part,but for to_i say it is nil but when i try that it says unidentified

Please i need some help on this problem

string = "123"
string = integer.to_i
string = float.to_f

1 Answer

Stephen Falck
Stephen Falck
7,558 Points

im assuming you are trying to convert the string into an integer and a float. In this case the reason its not correct is that you are performing your to_i and to_f methods on "integer" and "float" which have no values assigned to them and trying to assign the result to the variable "string"

integer = string.to_i
float = string.to_f

this will perform the methods on the string variable and save the result to new variables called integer and float