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,557 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