필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Antonio
Antonio 2015년 11월 14일
답변: Walter Roberson 2015년 11월 14일
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