The source code to convert the string into an integer is given below. The given program is compiled and executed successfully.
# Ruby program to convert the
# string into an integer
str = "10.5";
result = str.to_i();
print "Result: ",result;
Output:
Result: 10
Explanation:
In the above program, we created a variable str with an initial value "10.5". Then we converted the value of str into integer using the to_i() function and printed the result.
Program/Source Code:
The source code to convert the string into an integer is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a variable str with an initial value "10.5". Then we converted the value of str into integer using the to_i() function and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer