Ruby | Rational to_i() function

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for to_i() method
  
#Initialize rational number
rat1 = Rational(9, -2)
  
#Prints the rational number
           puts rat1.to_i()

chevron_right


Output:

-4

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for to_i() method
  
#Initialize rational number
rat1 = Rational(7)
  
#Prints the rational number
           puts rat1.to_i()

chevron_right


Output:

7
My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.