Filter löschen
Filter löschen

want a floating value?

2 Ansichten (letzte 30 Tage)
taher azim
taher azim am 11 Sep. 2016
Beantwortet: Walter Roberson am 11 Sep. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Sep. 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;

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by