How to round up all components of a matrix to nearest 'k' decimal
1 view (last 30 days)
Show older comments
Antonio
on 14 Nov 2015
Answered: Walter Roberson
on 14 Nov 2015
Hi,
Does anyone know how I can change this:
d =
0.017869069824194415755502531669223
-0.0050797537564829351997036551331211
-0.0077677772808408665487476505869037
to this:
d =
0.018
-0.005
-0.008
Actually I want to round it up in the 3rd decimal. Thanks.
0 Comments
Accepted Answer
Walter Roberson
on 14 Nov 2015
vpa(d,3)
We can tell from the number of decimal places that you show that you must be using symbolic numbers, so you can use vpa() to evaluate to a specific number of decimal places.
There is no way to round double precision numbers to a particular number of decimal places, because 0.1 is not exactly representable as a finite binary floating point number, for the same reasons that 1/7 is not exactly representable as a finite decimal number.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!