Ruby | Rational round() function Last Updated : 19 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The round() is an inbuilt function in Ruby returns rational rounded to the nearest value 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: rational.round(ndigits) Parameters: The function accepts a single parameter Return Value: It returns rational rounded to the nearest value with a precision of ndigits decimal digits. Example 1: Ruby # Ruby program for round() method # Initialize rational number rat1 = Rational(-4, 3) # Prints the rational number puts rat1.round() Output: -1 Example 2: Ruby # Ruby program for round() method # Initialize rational number rat1 = Rational('123.456') # Prints the rational number puts rat1.round(1) puts rat1.round(-1) Output: 247/2 120 Comment More infoAdvertise with us Next Article Ruby | Rational round() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Rational-class Similar Reads Ruby | Rational rational() function() The Rational() is an inbuilt method in Ruby returns the rational number of the form a/b. Syntax: Rational(num, den) Parameters: The function accepts two parameters which represents numerator and denominator. By default, the denominator is 1. Return Value: It returns the rational number of the form a 1 min read Ruby | Matrix round() function The round() is an inbuilt method in Ruby returns all the values of the matrix rounded to the given number of digits after decimal point. In case no parameter is passed, then 0 is assumed to be the default value. Syntax: mat1.round(num) Parameters: The function takes a non-mandatory parameter num to 1 min read Ruby | Rational rationalize() function The rationalize() is an inbuilt function in Ruby returns a simpler approximation of the value if the optional argument eps is given (rat-|eps| <= result <= rat+|eps|) otherwise returns its self. Syntax: rat.rationalize(eps) Parameters: The function accepts a single optional parameter Return Va 1 min read Ruby | Rational quo() function The quo() is an inbuilt function in Ruby returns the rational number by performing division. Syntax: rat1.quo(rat2) Parameters: The function accepts a single parameter Return Value: It returns the rational number by performing division Example 1: Ruby # Ruby program for quo() method # Initialize rat 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