Ruby Float rationalize() method with example Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Float rationalize() is a float class method which return the simple rational form (p/q) of a float value. Syntax: float.rationalize() Parameter: float value as argument Return: Simple approximation value Example #1: Ruby # Ruby program for rationalize() method # Initialize value a = 0.767 b = 2999.011 # Printing result puts "Rationalizing a : #{a.rationalize}\n\n" puts "Rationalizing b : #{b.rationalize}\n\n" Output : Rationalizing a : 767/1000 Rationalizing b : 2999011/1000 Example #2: Ruby # Ruby code for rationalize() method # Initialize value a = 0.767 b = 2999.011 c = 2.0000 # Printing result puts "Rationalizing a : #{a.rationalize(0.01)}\n\n" puts "Rationalizing b : #{b.rationalize(0.00001)}\n\n" puts "Rationalizing c : #{c.rationalize(0.1)}\n\n" Output : Rationalizing a : 10/13 Rationalizing b : 1634461/545 Rationalizing c : 2/1 Comment More infoAdvertise with us Next Article Ruby Float rationalize() method with example M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Float-class Similar Reads Ruby Float quo() method with example Float quo() is a float class method which return the quotient value of the division. Syntax: float.quo() Parameter: float values - dividend and divisor Return: Quotient value of the division. Example #1: Ruby # Ruby code for quo() method # Initializing value a = 4.0 b = 2.0 # Printing result puts 1 min read 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 to_r() method with example 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 1 min read Ruby Float arg() method with example Float arg() is a float class method which works on float values and works differently for both positive and negative values. Syntax: float.arg() Parameter: float value which is to be checked Return: return 0 for positive values. Otherwise pi(3.141592653589793) Example #1: Ruby # Ruby code for arg() 1 min read Ruby Float fdiv() method with example Float fdiv() is a float class method which return a division value of the form p/q. Syntax: float.fdiv() Parameter: values to divide - p and q Return: Division value - Quotient Example #1: Ruby # Ruby program for fdiv() method # Initializing value a = 2.0.numerator() # returning machine dependent re 1 min read Like