Skip to main content
v2026.11,986 entries · CC-BY 4.0

MATLAB Round: Syntax, Decimals, Significant Digits and Ties

MATLAB round syntax for integers, decimals, significant digits and tie-breaking, with NumPy and Octave tie rules compared and the display-versus-stored trap.

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

  1. 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.
  2. Round to a number of decimal places. Use round(pi,3), which returns 3.1420 (the display shows four decimals under the default format; the value is 3.142).
  3. Round to the left of the decimal point. A negative N counts digits left of the point: round(863178137,-2) returns 863178100. Use -1 for the nearest 10, -2 for the nearest 100.
  4. 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".
  5. Choose how ties are broken. Add the TieBreaker name-value argument: round(-2.5:1:2.5,TieBreaker="even") returns [-2 -2 0 0 2 2], while TieBreaker="fromzero" (the default) returns [-3 -2 -1 1 2 3].
  6. Round durations. For a duration t, round(t) rounds to the nearest second and round(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

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.

Tie-breaking and rounding direction of MATLAB, Octave and NumPy rounding functions
Function or settingToolRuleDocumented example
round (default, TieBreaker fromzero)MATLABNearest integer; ties away from zero-2.5:1:2.5 gives -3 -2 -1 1 2 3
round with TieBreaker=evenMATLABNearest integer; ties to even-2.5:1:2.5 gives -2 -2 0 0 2 2
fixMATLABToward zero[-1.9 -3.4; 1.6 2.5; -4.5 4.5] gives [-1 -3; 1 2; -4 4]
roundGNU OctaveNearest integer; ties further from zeroround([-2.7,2.7]) gives -3 3; 2.5 gives 3
roundbGNU OctaveNearest integer; ties to evenBanker's rounding
numpy.roundNumPyTies to nearest even value[.5,1.5,2.5,3.5,4.5] gives [0,2,2,4,4]

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about MATLAB Round: Syntax, Decimals, Significant Digits and Ties

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →