Open In App

Ruby | Rational to_i() function

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
The to_i() is an inbuilt function in Ruby returns the truncated integer value
Syntax: rat.to_i() Parameters: The function accepts no parameter Return Value: It returns the truncated integer value
Example 1: CPP
#Ruby program for to_i() method

#Initialize rational number
rat1 = Rational(9, -2)

#Prints the rational number
           puts rat1.to_i()
Output:
-4
Example 2: CPP
#Ruby program for to_i() method

#Initialize rational number
rat1 = Rational(7)

#Prints the rational number
           puts rat1.to_i()
Output:
7

Next Article

Similar Reads