필터 지우기
필터 지우기

how do I print number to 1dp - or 0 dp if an integer?

조회 수: 3 (최근 30일)
tombola
tombola 2012년 3월 26일
Hi, I guess the title says it all.
I'm using
MATLAB code
sprintf('%.0f', testval) %to print to 0 dp
sprintf('%.1f', testval) %to print to 1 dp
Is there a way to (simply) print to 0dp if testval is an integer, but 1dp if it has any decimal part?
Thanks a lot,
Tom.

채택된 답변

Wayne King
Wayne King 2012년 3월 26일
You can use rem()
rem(1.5,1) % gives 0.5
while
rem(3,1) % gives 0
testval = 3.5;
if (rem(testval,1)~=0)
disp('testval has a decimal part');
else
disp('testval is an integer');
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Additional Math and Discrete에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by