MATLAB: Want a floating value

double value of a variable

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.

Best Answer

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;