Decimal Round

This function rounds numbers to any given precision.
424 Downloads
Updated 10 Jul 2013

View License

% Alex May
% February 5, 2013
% decround v1.0
%
% decround(in,place,type) is a function that rounds any number to the
% specified decimal place.
%
% place specifies where the rounding should take place. 0 is the one's
% place, 1 is the tenth's place, 2 is the hundredth's place, etc. Negative
% place input specifies places to the left of the decimal.
%
% Type is a string 'nearest', 'up', or 'down' and specifies the direction
% in which rounding should take place.
%
% Examples:
% decround(pi,2,'nearest')
% ans = 3.14
%
% decround(pi,2,'up')
% ans = 3.15
%
% decround(pi,2,'down')
% ans = 3.14
%
% decround(33628,-3,'nearest')
% ans = 33600
%
% decround(33628,-3,'up')
% ans = 33700
%
% decround(33628,-3,'down')
% ans = 33600

Cite As

Alex May (2026). Decimal Round (https://www.mathworks.com/matlabcentral/fileexchange/42572-decimal-round), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.0.0.0