How can I round a number to any precision I define?
28 views (last 30 days)
Show older comments
I would like to round a number to the nearest hundredth or to any other precision that I define.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The ability to round a number to a custom precision is available in the ROUNDN function, as part of the Mapping Toolbox.
If you do not have the Mapping Toolbox, you may work around this issue as in the following code:
a = rand(1);
n = -2;
ra = round(a*10^(-n))/(10^(-n));
In the code above, 'n' is the desired power of ten that you would like to round to.
0 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!