Ruby | Rational to_f() function Last Updated : 19 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The to_f() is an inbuilt function in Ruby returns the float value Syntax: rat.to_f() Parameters: The function accepts no parameter Return Value: It returns the float value Example 1: CPP #Ruby program for to_f() method #Initialize rational number rat1 = Rational(9, -2) #Prints the rational number puts rat1.to_f() Output: -4.5 Example 2: CPP #Ruby program for to_f() method #Initialize rational number rat1 = Rational(7) #Prints the rational number puts rat1.to_f() Output: 7.0 Comment More infoAdvertise with us Next Article Ruby | Rational fdiv() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Rational-class Similar Reads Ruby | Rational to_r() function The to_r() is an inbuilt function in Ruby returns it's own value Syntax: rat.to_r() Parameters: The function accepts no parameter Return Value: It returns it's own value Example 1: CPP #Ruby program for to_r() method #Initialize rational number rat1 = Rational(18, -4) #Prints the rational number put 1 min read 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: CPP #Ruby program for to_i() method #Initialize rational number rat1 = Rational(9, -2) #Print 1 min read Ruby | Rational to_s() function The to_s() is an inbuilt function in Ruby returns value as string Syntax: rat.to_s() Parameters: The function accepts no parameter Return Value: It returns value as string Example 1: CPP #Ruby program for to_s() method #Initialize rational number rat1 = Rational(18, -4) #Prints the rational number p 1 min read Ruby | Rational fdiv() function The fdiv() is an inbuilt function in Ruby returns float by performing division. Syntax: rat.fdiv(numeric)Parameters: The function accepts a single parameterReturn Value: It returns float by performing division  Example 1:  Ruby # Ruby program for fdiv() method # Initialize rational number rat1 = 1 min read Ruby | Rational floor() function The floor() is an inbuilt function in Ruby returns the largest number less than or equal to rat with a precision of ndigits decimal digits. ndigits by default is 0. It returns a rational when ndigits is positive, otherwise returns an integer. Syntax: rat.floor(ndigits) Parameters: The function accep 1 min read Ruby | Rational abs() function The abs() is an inbuilt function in Ruby returns the absolute value of rational. Syntax: rational.abs() Parameters: The function accepts no parameter Return Value: It returns returns the absolute value of rational. Example 1: Ruby # Ruby program for abs() method # Initialize rational number rat1 = R 1 min read Like