Decimal Round
% 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 (2024). Decimal Round (https://www.mathworks.com/matlabcentral/fileexchange/42572-decimal-round), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |