No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.3 | 12 ratings Rate this file 5 Downloads (last 30 days) File Size: 1.65 KB File ID: #6077 Version: 1.0




20 Oct 2004 (Updated )

Round to a specified number of decimals.

| Watch this File

File Information

ROUND2 Round to a specified number of decimals.

  ROUND2(A) returns the same as ROUND(A).
  ROUND2(A, 'even') returns the same as ROUND(A). Elements with
  fractional part equal to 0.5 are rounded to even integers.
  ROUND2(A, N) rounds the elements of A to decimals specified in N.
  ROUND2(A, N,'even') rounds the elements of A to decimals specified
  in N. Elements with 5 as the (N+1)-th digit after decimal are rounded
  to even numbers.

  See also: ROUND, FIX, FLOOR, CEIL, FIX2.


This file inspired Round To Specified Digits Place, Round To A Specified Number Of Significant Digits, Roundfrac, and Rounding Functions Collection And Cheat Sheet.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
26 Jul 2013 Andrew Horchler  
18 Apr 2012 Edward Zechmann

Roundn is in the Mapping Toolbox which costs approximately $1,000.00 for a single user license. It is much simpler; however, it has fewer features and costs $1,000.00. The syntax for using roundn is reproduced from the Mathworks website to help anyone who reads this comment thread. Please let me know if a program with the simple syntax of Roundn would be of benefit to the Matlab Central Users Community.

roundn - Round to multiple of 10n


roundn(x,n) rounds each element of x to the nearest multiple of 10n. The variable n must be scalar, and integer-valued. For complex x, the imaginary and real parts are rounded independently. For n = 0, roundn gives the same result as round. That is, roundn(x,0) == round(x).

Comment only
06 Apr 2012 Humayun Kathuria

Guys! Use "roundn" if you want to use a simple MATLAB built-in function.

12 Jan 2012 Nikolaos


14 Aug 2011 Soumyadipta Sarkar

Thank you Mukhtar. You saved my day.

19 Jul 2010 Daniel

Daniel (view profile)

Thanks a lot! Unbelievable Matlab does not have one in their main functions!

14 Oct 2008 Senthilkumaran K

Ohh.. Now I could understand, why I did not get roundn function. I didn't install Mapping tool box in R2007b. ThxJohn Greeb for the info.

11 Oct 2008 Srikant Vallabhajosula

works for me!!! great timely help!!!

08 Jun 2008 Kian Chai

Thanks a lot

Comment only
30 Apr 2008 John Greeb

Regarding roundn- I found it in the Mapping toolbox from MATLAB.

Comment only
27 Apr 2008 Amita Deb

This seems very useful. I am surprised that MATLAB doesn't have a built-in function to to rounding-off up to a desired number of decimal places.

18 Feb 2008 Angel Atanasov

Thank you. Great addition for me. :)

05 Feb 2008 Mukhtar Ullah

Senthilkumaran, I could not find roundn in MATLAB R2007b. May be you have mistyped it? It will be very interseting to know if there is a function like that.

Comment only
11 May 2007 Senthilkumaran K

Hi... Do u have any idea about roundn function..
I used it in R14 version but couldn't find it in 2006b. Anyway your code helped to bridge that gap.

Comment only
11 Apr 2006 Kurt Rosenberger  
11 Sep 2005 Serena F.

Same comments as Johnny C. except for the "||" and "&&" substitution.

02 Aug 2005 Mukhtar Ullah

Oliver Lockwood,
Surely, what you said forms the core of this file; but if you look the help documentation, ROUND2 does more than that. Like when you need rounding to even in 0.5 case.

Comment only
19 Jul 2005 Oliver Lockwood

Surely this can be done far more simply by the following method, e.g. if you want to round variable mynum to 4 d.p.:

mynum = (round(mynum*1e4)) / 1e4 ;

Please let me know your thoughts.

Comment only
13 Apr 2005 Johnny C.

A good idea, just what I needed. The function probably works as such in R14 which is the intended environment.

However, I'm using R12.1 and I had to replace "tf = @(x) abs(x - fix(x)) == .5" by "tf = inline('abs(x - fix(x)) == .5')", "||" by "|" and "&&" by "&" and comment away the check for non-scalar input (R12.1 doesn't have the function "isscalar") to make it work.

If it worked right away in a previous Matlab release, I'd rate it at 4.

21 Oct 2004

improved version

14 Apr 2005

major bug fixed!

14 Apr 2005

another hidden bug fixed!

Contact us