How to round up all components of a matrix to nearest 'k' decimal

2 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2015-11-14
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 个)

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by