×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

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

Last Updated : December 15, 2025

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!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.