Main Content

roundn

Round to multiple of 10n

roundn is not recommended. Use round instead.

Syntax

roundn(x,n)

Description

roundn(x,n) rounds each element of x to the nearest multiple of 10n. 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).

Examples

Round pi to the nearest hundredth.

roundn(pi, -2)
ans =

    3.1400

Round the equatorial radius of the Earth, 6378137 meters, to the nearest kilometer.

roundn(6378137, 3)
ans =

     6378000

See Also

round

Introduced before R2006a