Ruby Float to_r() method with example Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Float to_r() is a float class method which return a rational form of the float value. Syntax: float.to_r() Parameter: float value as argument Return: Rational form representation of the float value. Example #1 : Ruby # Ruby code for to_r() method # Initializing values a = 2.0 b = 9.99991 # Printing result puts "Rational form of a : #{a.to_r}\n\n" puts "Rational Form of b : #{b.to_r}\n\n" Output : Rational form of a : 2/1 Rational Form of b : 21990034643427/2199023255552 Example #2 : Ruby # Ruby code for to_r() method # Initializing value a = 0.767 b = 2797999.011 # Printing result puts "Rational form of a : #{a.to_r}\n\n" puts "Rational Form of b : #{b.to_r}\n\n" Output : Rational form of a : 6908521828386341/9007199254740992 Rational Form of b : 375541070202667/134217728 Comment More infoAdvertise with us Next Article Ruby Integer to_f function with example M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Float-class Similar Reads Ruby Integer to_r function with example The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: Ruby # Ruby program for to_r function # Initializi 1 min read Ruby Integer to_r function with example The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: Ruby # Ruby program for to_r function # Initializi 1 min read Ruby Integer to_f function with example The to_f function in Ruby converts the value of the number as a float. If it does not fit in float, then it returns infinity. Syntax: number.to_f Parameter: The function takes the integer which is to be converted to float. Return Value: The function returns the float value of the number. Example #1: 1 min read Ruby Integer to_f function with example The to_f function in Ruby converts the value of the number as a float. If it does not fit in float, then it returns infinity. Syntax: number.to_f Parameter: The function takes the integer which is to be converted to float. Return Value: The function returns the float value of the number. Example #1: 1 min read Ruby Integer to_int function with example The to_int function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. It is an alias of to_i function. Syntax: number.to_int Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int valu 1 min read Ruby Integer to_int function with example The to_int function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. It is an alias of to_i function. Syntax: number.to_int Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int valu 1 min read Like