Written and maintained by CASRAI Editorial Board
Published
On this page
round in MATLAB rounds each element of an array to the nearest integer, and with a second argument it rounds to a chosen number of decimal places, to a power of ten on the left of the decimal point, or to significant digits. Y = round(X) sends halves away from zero (2.5 becomes 3, -2.5 becomes -3). round(X,N) keeps N digits right of the decimal point, and round(X,N,"significant") counts N digits from the leftmost digit. The sections below cover each form, the tie-breaking options, and the display trap that makes correct results look wrong. Everything here was checked against the MathWorks documentation for round on 2026-11-12.
What round is used for in research
Researchers use round to prepare numbers for reporting: limiting a table of means to two decimals, converting a fractional index to a whole sample count, snapping a measurement to the nearest 10 or 100 units, or reporting a result to a fixed number of significant digits. It works element-wise on arrays and also accepts durations and tables. Because it changes the stored value rather than only the display, it belongs at the end of an analysis, not in the middle of a chain of calculations where rounding error would compound. Related functions on this site cover computing averages in MATLAB and the constant pi in MATLAB, two common sources of values you will then round.
Install or access
round is a built-in MATLAB function, so no toolbox is needed. Get MATLAB from the MathWorks website (mathworks.com) or through your institution’s licence, and open the official reference page for round at mathworks.com/help/matlab/ref/double.round.html for the syntax of your release. MATLAB Online runs in a browser with a MathWorks account. The free alternatives table below lists open-source options if you do not have a licence.
Step-by-step: rounding a value in MATLAB
- Round to the nearest integer. Type
round([2.11 3.5; -3.5 0.78])in the Command Window. The result is[2 4; -4 1]: 3.5 goes up to 4 and -3.5 goes down to -4, because ties move away from zero. - Round to a number of decimal places. Use
round(pi,3), which returns3.1420(the display shows four decimals under the default format; the value is 3.142). - Round to the left of the decimal point. A negative N counts digits left of the point:
round(863178137,-2)returns863178100. Use -1 for the nearest 10, -2 for the nearest 100. - Round to significant digits. Add the
"significant"type:round([1253 1.345 120.44],2,"significant")returns[1300 1.3 120]. N must be a positive integer and is counted from the leftmost digit. For example,round(3132,2,"significant")is 3100. The default type is"decimals". - Choose how ties are broken. Add the
TieBreakername-value argument:round(-2.5:1:2.5,TieBreaker="even")returns[-2 -2 0 0 2 2], whileTieBreaker="fromzero"(the default) returns[-3 -2 -1 1 2 3]. - Round durations. For a duration
t,round(t)rounds to the nearest second andround(t,"hours")to the nearest hour.
Syntax and option summary
| Form | What N or the option does | Documented example |
|---|---|---|
round(X) |
Nearest integer | [2.11 3.5; -3.5 0.78] gives [2 4; -4 1] |
round(X,N), N > 0 |
N digits right of the decimal point | round(pi,3) gives 3.142 |
round(X,N), N = 0 |
Nearest integer | Same as round(X) |
round(X,N), N < 0 |
|N| digits left of the decimal point | round(863178137,-2) gives 863178100 |
round(X,N,"significant") |
N significant digits, counted from the leftmost digit | round(3132,2,"significant") gives 3100 |
round(___,TieBreaker=direction) |
Sets the tie rule: "fromzero" (default), "tozero", "even", "odd", "plusinf", "minusinf" |
TieBreaker="even" on -2.5:1:2.5 gives [-2 -2 0 0 2 2] |
round(t), round(t,unit) |
Rounds a duration to seconds, or to the named unit | round(t,"hours") |
Per the documentation, X can be single, double, any signed or unsigned integer type, char, logical, a table or a timetable. When you supply more than one input, X must be single, double, a table or a timetable. For complex input, the real and imaginary parts are rounded separately.
Output and how to read it
The output has the same size as the input, with every element rounded. The same rules apply to every element, so a matrix is rounded entry by entry. Compare round with its neighbours on the same input. The documentation example for fix, which rounds toward zero, takes X = [-1.9 -3.4; 1.6 2.5; -4.5 4.5] and returns [-1 -3; 1 2; -4 4]. Applying round to the same input gives [-2 -3; 2 3; -5 5] by the ties-away-from-zero rule. floor rounds toward negative infinity and ceil toward positive infinity (Octave documentation, same definitions). Use round when you want the nearest value, fix when you want truncation toward zero, and floor or ceil when direction matters, such as bin edges or a required minimum sample size.
Troubleshooting
round(x,1) gives a result that does not match what is displayed
MATLAB’s documentation describes this case: x = 112.05 - 110 displays as 2.0500, but the stored value is slightly less than 2.05, so round(x,1) returns 2. The cause is binary floating point. A double uses 64 bits (1 sign bit, 11 exponent bits, 52 mantissa bits), and the MATLAB documentation states that some numbers are not represented exactly; for instance 1-3*(4/3-1) returns 2.2204e-16 instead of 0. The fix is to understand that round acts on the stored value, not on what the Command Window shows.
The Command Window shows the wrong number of digits
The default format short displays four digits after the decimal point, so pi appears as 3.1416; format long shows 15 digits after the decimal point for double (7 for single), so pi appears as 3.141592653589793. The MathWorks documentation states that numeric formats affect only how numbers appear in the display, not how MATLAB computes or saves them. To control the displayed digits without touching the value, use sprintf; to change the value, use round.
Arguments are rejected
If you pass digits, a type or a tie breaker, check that X is single, double, table or timetable; integer, char and logical inputs are listed for the single-argument form only. Also check that for "significant", N is a positive integer. The "significant" type and TieBreaker option appear in the current reference page, so if your installed release rejects them, consult the reference page for your release.
Free alternatives and how their rounding differs
If you move an analysis between tools, the tie rule is the most common source of changed results. The data table below the FAQ compares tie behaviour across the functions discussed here. This table covers what each free tool can do.
| Tool | Function | Digits argument | Documented tie behaviour |
|---|---|---|---|
| GNU Octave | round |
Documented with one argument, to the nearest integer | Ties go further away from zero (2.5 to 3, -2.5 to -3) |
| GNU Octave | roundb |
One argument | Ties go to the even integer (banker’s rounding) |
| NumPy (Python) | numpy.round(a, decimals=0) |
Yes; negative decimals count positions left of the decimal point |
Ties go to the nearest even value: 1.5 and 2.5 both give 2.0 |
NumPy’s documentation also warns that numpy.round uses a fast but sometimes inexact algorithm for decimals, and gives np.round(16.055,2) as 16.06 where Python’s built-in round(16.055,2) gives 16.05. Python users can read more in our guide to NumPy round.
Because MATLAB’s default sends ties away from zero while NumPy sends them to even, round([0.5 1.5 2.5 3.5 4.5]) in MATLAB gives [1 2 3 4 5], whereas np.round([.5,1.5,2.5,3.5,4.5]) in NumPy gives [0,2,2,4,4]. If you need MATLAB to match NumPy, set TieBreaker="even". For other MATLAB basics, see comparing strings in MATLAB.
Frequently asked questions
How do I round to 2 decimal places in MATLAB?
Use round(X,2). For example, round(pi,3) returns 3.142 for three places, and N = 2 works the same way. If the Command Window shows fewer or more digits than you expect, that is the display format, not the value.
How do I round to the nearest 10 or 100?
Use a negative N. round(X,-1) rounds to the nearest 10 and round(X,-2) to the nearest 100; the documentation example is round(863178137,-2), which returns 863178100.
How does MATLAB round .5 values?
By default, away from zero to the integer with larger magnitude: 2.5 becomes 3 and -2.5 becomes -3. Use TieBreaker with "tozero", "even", "odd", "plusinf" or "minusinf" to change it.
What is the difference between round, fix, floor and ceil?
round goes to the nearest integer, fix toward zero, floor toward negative infinity, ceil toward positive infinity. On -4.5 and 4.5, fix returns -4 and 4.
Why does round(x,1) give an unexpected result?
The stored binary value can differ slightly from the displayed decimal. MathWorks’ example: 112.05 - 110 displays 2.0500, is stored slightly below 2.05, and round(x,1) returns 2.
How do I round to significant digits?
Use round(X,N,"significant"); round([1253 1.345 120.44],2,"significant") returns [1300 1.3 120].
Sources
- MathWorks, round (MATLAB documentation), read 2026-11-12.
- MathWorks, format, read 2026-11-12.
- MathWorks, fix, read 2026-11-12.
- MathWorks, Floating-point numbers, read 2026-11-12.
- NumPy, numpy.round, read 2026-11-12.
- GNU Octave, Utility Functions, read 2026-11-12.
Data: Tie-breaking and rounding direction of MATLAB, Octave and NumPy rounding functions
Compares how documented rounding functions treat exact halves and direction, compiled from the official MATLAB, GNU Octave and NumPy documentation pages, with the documented example inputs and outputs.
Period covered: 2026.
| Function or setting | Tool | Rule | Documented example |
|---|---|---|---|
| round (default, TieBreaker fromzero) | MATLAB | Nearest integer; ties away from zero | -2.5:1:2.5 gives -3 -2 -1 1 2 3 |
| round with TieBreaker=even | MATLAB | Nearest integer; ties to even | -2.5:1:2.5 gives -2 -2 0 0 2 2 |
| fix | MATLAB | Toward zero | [-1.9 -3.4; 1.6 2.5; -4.5 4.5] gives [-1 -3; 1 2; -4 4] |
| round | GNU Octave | Nearest integer; ties further from zero | round([-2.7,2.7]) gives -3 3; 2.5 gives 3 |
| roundb | GNU Octave | Nearest integer; ties to even | Banker's rounding |
| numpy.round | NumPy | Ties to nearest even value | [.5,1.5,2.5,3.5,4.5] gives [0,2,2,4,4] |
Sources
- MATLAB round (accessed 2026-11-12)
- MATLAB fix (accessed 2026-11-12)
- GNU Octave Utility Functions (accessed 2026-11-12)
- numpy.round (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







