ADVERTISEMENT
ADVERTISEMENT

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

Ruby Example: Write a program to convert a numeric string into integer using to_i() function.
Submitted by Nidhi, on January 06, 2022

Problem Solution:

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.

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.

Ruby Strings Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.