File Exchange

image thumbnail

RoundX - Round to desired precision

version 1.0 (1.5 KB) by

Rounds the elements of X with the desired precision.



View License

Rounds the elements of X with the desired precision. Better than similar submissions as it handles arrays, negative and positive precision values, and ceil and floor functionality. It also is very tolerant to different numbers of inputs so it can be used as a direct replacement for round.

%ROUNDX rounds the elements of X with the desired precision
% output = roundx(X)
% output = roundx(X, decimalplaces)
% output = roundx(X, decimalplaces, options)
% X is the value to be rounded. X can be an array, if desired.
% DECIMALPLACES is the number of decimal places to round to. Also accepts
% 0 and negative values, used to round to desired sig. figs.
% OPTIONS can be 'ceil', 'floor', or 'round' and indicates to the function
% whether to round up, down, or to the closest value, respectively.
% Default is 'round' if excluded.
% Author: David Berman (

Comments and Ratings (4)

Yee Jack

Nice work!!!


Eoghan (view profile)

Anne Tishley

MATLAB Release
MATLAB 8.1 (R2013a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video