Borrar filtros
Borrar filtros

want a floating value?

2 visualizaciones (últimos 30 días)
taher azim
taher azim el 11 de Sept. de 2016
Respondida: Walter Roberson el 11 de Sept. de 2016
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Sept. de 2016
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;

Más respuestas (0)

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by