×

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 the string into an integer

Last Updated : December 15, 2025

Problem Solution

In this program, we will create a variable with a string value. Then we will convert a string value into an integer using the to_i() function.

Program/Source Code

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.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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