Ruby Float to_r() method with example Last Updated : 07 Jan, 2020 Comments Improve Suggest changes 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 Float to_r() method with example M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Float-class Similar Reads Ruby Float modulo() method with example Float modulo() is a float class method which return the remainder value on dividing two float values. Syntax: float.modulo() Parameter: remainder value from the operation p/q Return: Modulo i.e. Remainder Example #1: Example for modulo() method Ruby # Ruby program for modulo() method # Initilizig va 1 min read Ruby Float divmod() method with example Float divmod() is a float class method that returns an array having the quotient and remainder on dividing two numbers. Syntax: float.divmod()Parameter: float values - dividend and divisorReturn: An array with quotient and remainder. Example #1:Â Ruby # Ruby code for divmod() method # Initializing v 1 min read Ruby Float coerce() method with example coerce() is a float class method which return the ceil value of the passed float value. Syntax: float.coerce() Parameter: numeric values (can be integer as well as float value) Return: An array with both float and numeric value represented in the form of Float objects. Example #1 : Ruby # Ruby code 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 Like