Ruby | Numeric round() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The round() is an inbuilt method in Ruby returns a number rounded to a number nearest to the given number with a precision of the given number of digits after the decimal point. In case the number of digits is not given, the default value is taken to be zero. Syntax: num.round(ndigits) Parameters: The function needs a number and ndigits which specifies the number of digits to be rounded off. If ndigits is not given then, default value is taken to be zero. Return Value: It returns the rounded value. Example 1: Ruby # Ruby program for round() # method in Numeric # Initialize a number num1 = -16.7834 num2 = -16.78324 num3 = 16.873 # Prints round puts num1.round(1) puts num2.round() puts num3.round() Output: -16.8 -17 17 Example 2: Ruby # Ruby program for round() # method in Numeric # Initialize a number num1 = 12.32 num2 = -1321.998321 num3 = -12.2321 # Prints round puts num1.round(1) puts num2.round(2) puts num3.round(3) Output: 12.3 -1322.0 -12.232 Comment More infoAdvertise with us Next Article Ruby | Numeric round() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Numeric-class Similar Reads Ruby | Numeric quo() function The quo() is an inbuilt method in Ruby returns the most exact division, whether it be a float or a rational one. Syntax: num.quo() Parameters: The function needs a number which is to be checked. Return Value: It returns the most exact division. Example 1: Ruby # Ruby program for quo() # method in Nu 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 | Numeric real() function The real() is an inbuilt method in Ruby returns the real part of the given number. Syntax: num.real() Parameters: The function needs the number whose real part is to be returned. Return Value: It returns the real part of the complex number. Example 1: Ruby # Ruby program for real() # method in Numer 1 min read Ruby | Numeric real? function The real?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false. Syntax: num.real?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # Ruby pr 1 min read Ruby | Numeric remainder() function The remainder() is an inbuilt method in Ruby returns the remainder when num1 is divided by num2. Syntax: num1.remainder(num2) Parameters: The function needs num1 and num2 which are to be divided. Return Value: It returns the remainder. Example 1: Ruby # Ruby program for remainder() # method in Numer 1 min read Like