|
|
| File Information |
| Description |
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
>> round2(pi,0.01)
ans =
3.14
Example 2: round PI to 4 decimal places
>> round2(pi,1e-4)
ans =
3.1416
Example 3: round PI to 8-bit fraction
>> round2(pi,2^-8)
ans =
3.1406
Examples 4-6: round PI to other multiples
>> round2(pi,0.05)
ans =
3.15
>> round2(pi,2)
ans =
4
>> round2(pi,5)
ans =
5 |
| Acknowledgements |
This file inspired
Round2 Dp, Graph Digitzer, Round, Ceil And Floor Matlab Datenumbers, Round To A Specified Number Of Significant Digits, and Round To Specified Digits Place.
|
| MATLAB release |
MATLAB 6.5 (R13)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Updates |
| 29 Jun 2006 |
Expanded help text with examples, including binary fraction (analagous to fixed point math). |
| 12 Jan 2010 |
copyright |
| 07 Jun 2010 |
Minor bug fix (error message typo) |
|
Contact us