Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Round to nearest decimal or integer

`Y = round(X)`

`Y = round(X,N)`

`Y = round(X,N,type)`

`Y = round(t)`

`Y = round(t,unit)`

`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 exactly `0.5`

,
the `round`

function rounds away from zero to the
integer with larger magnitude.

`format short`

and`format long`

both display rounded numbers. This can cause unexpected results when combined with the`round`

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 of`pi`

(and no trailing zeros), use`sprintf('%.2f',pi)`

.

Was this topic helpful?