필터 지우기
필터 지우기

want a floating value?

조회 수: 2 (최근 30일)
taher azim
taher azim 2016년 9월 11일
답변: Walter Roberson 2016년 9월 11일
t1=14;
t2=int16(2.2*14);
y=t2/t1
y=2
but i want a floating value or double of y i.e y=2.2143 in answer but it is showing me a integer value. help me in sorting this out.

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 11일
You have a integer data type in an operation with a double precision data type (t1 = 14 is double precision.) MATLAB defines an operation combining an integer data type and double precision as being carried out in double precision and then converted to the integer data type. Your code is currently equivalent to
y = int16( double(t2) / t1 );
If that is not what you want, then you should either not make t2 into int16, or else you should convert it before the division:
y = double(t2) / t1;

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by