round
Round to nearest decimal or integer
Syntax
Description
Y = round(
rounds each element of
X
)X
to the nearest integer. In the case of a tie, where an
element has a fractional part of 0.5
(within roundoff error)
in decimal, the round
function rounds away from zero to the
nearest integer with larger magnitude.
Examples
Input Arguments
Tips
format short
andformat long
both display rounded numbers. This display can cause unexpected results when combined with theround
function.For display purposes, use
sprintf
to control the exact display of a number as a string. For example, to display exactly 2 decimal digits ofpi
(and no trailing zeros), usesprintf("%.2f",pi)
.