want a floating value?

2 次查看(过去 30 天)
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