필터 지우기
필터 지우기

Round floating number without zeros

조회 수: 15 (최근 30일)
loes visser
loes visser 2016년 11월 24일
댓글: loes visser 2016년 11월 24일
Hi,
I have an array with multiple floating value's. I would like to round them to the nearest two digit number. I used
round(x,2)
This rounds 1.32456778 to 1.3200000. But I would like the result 1.32 (without the zeros). Because I want to display the value in a graph as text, and now it displays 1.320000E+00
qq = 24;
qw = 41.2;
y = sprintf('Vote = %d', round(x,2) );
qe = text(qq,qw,y, 'FontWeight', 'bold', 'FontSize', 8);
Can someone help me?
  댓글 수: 1
Jos (10584)
Jos (10584) 2016년 11월 24일
what is the variable x in your code?

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

채택된 답변

Jos (10584)
Jos (10584) 2016년 11월 24일
Use %f as a format holder rather than %d, and specify the number of decimals, like this
x = 1.320001
sprintf('%.2f',x)

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by