Round off error (Wrong format)

조회 수: 16 (최근 30일)
Mantej Sokhi
Mantej Sokhi 2022년 9월 19일
편집: Mantej Sokhi 2023년 10월 22일
Suppose I have a number .. let's say x = 1.4534567809385. If I want to round this off to 5 decimal digits I should get x = 1.45346. However when I try doing this in Matlab using the round function or creating my own function to round it off to 5 decimal digits I am always getting 4 decimal digits. How can I fix this ?

채택된 답변

Image Analyst
Image Analyst 2022년 9월 19일
It's just displaying 4 places because you're using format short. Switch to format long and you'll see it correctly.
x = 1.4534567809385;
x5 = round(x, 5)
x5 = 1.4535
format long
x = 1.4534567809385;
x5 = round(x, 5)
x5 =
1.453460000000000
  댓글 수: 2
Mantej Sokhi
Mantej Sokhi 2022년 9월 19일
Ah .. thanks a lot for a prompt reply.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by