Updated 1 Sep 2016
Everyone knows about the ROUND function for converting floating point values to their nearest whole number or integer value, but have you ever wanted to round off values to something other than whole numbers? This simple utility function does just that.
Example 1: round PI to 2 decimal places
Example 2: round PI to 4 decimal places
Example 3: round PI to 8-bit fraction
Examples 4-6: round PI to other multiples
Robert Bemis (2023). round2 (https://www.mathworks.com/matlabcentral/fileexchange/4261-round2), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired: Round to Specified Digits Place, Round to a Specified Number of Significant Digits, Graph Digitzer, Round, Ceil and Floor Matlab-datenumbers, roundfrac, ROUND2DP
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.