Ruby | Matrix round() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 which the values in the matrix are rounded to. In case num is not passed, it is assumed to be zero. Return Value: It returns the matrix with all values rounded to num digits after decimal point. Example 1: Ruby # Ruby program for round() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1.878787, 21.8449], [31.7382, 18.7382]] # Prints all values of matrix # rounded by 2 puts mat1.round(2) Output: Matrix[[1.88, 21.84], [31.74, 18.74]] Example 2: Ruby # Ruby program for round() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[6.4334, 432.432], [54.342, 323.213]] # Prints all values of matrix # rounded by 0 which is default puts mat1.round() Output: Matrix[[6, 432], [54, 323]] Comment More infoAdvertise with us Next Article Ruby | Matrix row() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix row() function The row() is an inbuilt method in Ruby returns a vector that contains all the elements in the given row-number. Syntax: mat1.row(num) Parameters: The function takes a mandatory parameter row, whose elements are to be returned in a vector. Return Value: It returns a vector containing all the elements 1 min read Ruby | Matrix rank() function The rank() is an inbuilt method in Ruby returns the rank of the given matrix. The float values can yield enormous results due to float precision Syntax: mat1.rank() Parameters: The function does not accepts any parameter. Return Value: It returns the rank of the current matrix. Example 1: CPP #Ruby 1 min read Ruby | Numeric round() function 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: T 1 min read Ruby | Matrix real() function The real() is an inbuilt method in Ruby returns a matrix with only real part in it. The other index are assigned to zero. Syntax: mat1.real() Parameters: The function does not takes any parameter. Return Value: It returns a matrix with only real part. Example 1: CPP #Ruby program for real() method i 1 min read Ruby | Matrix real?() function The real?() is an inbuilt method in Ruby returns a boolean value. It returns true if all values in the matrix are real, else it returns false. Syntax: mat1.real?() Parameters: The function needs the matrix which is to be checked for real values Return Value: It returns true if it all values are real 1 min read Ruby | Matrix rect() function The rect() is an inbuilt method in Ruby returns two matrix. The first matrix returned has all the real values of the matrix, and the second matrix has all the imaginary values in the matrix. Syntax: mat1.rect() Parameters: The function needs the matrix whose real and imaginary values are to be retur 1 min read Like