Q:

Ruby program to convert a numeric string into integer using to_i() function

0

In this program, we will create a string initialized with a numeric string. Then we will convert the numeric string into integer using to_i() and return the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to covert a numeric string into integer using the to_i() function is given below. The given program is compiled and executed successfully.

# Ruby program to covert a numeric string 
# into integer using to_i() function

str = "4536";

num = str.to_i();

print "Number is: ",num,"\n";

Output:

Number is: 4536

Explanation:

In the above program, we created a string str initialized with "4536". Then we used the to_i() function to convert the numeric string into integer and assigned the result to the num variable. After that, we printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now