MATLAB: Decimal places when multiplying by 1.1

decimalsMATLAB and Simulink Student Suitemultiplicationquick-questionsimple questionvalueworkspace

Hello,
I just ran into this weird situation. I am just genuinely curious to know why Matlab behaves this way. Let's say that I have the following variables set in Matlab:
a = 0.9000
b = 1.1000
c = 1.2000
If I multiply the variables above by 100 I get the following results:
>> a * 100
ans =
90
>> b * 100
ans =
110.0000
>> c * 100
ans =
120
When multiplying a number by 1.1000 always yields four decimal places. I had a script running into error due to these decimal places – I had to use round() to get rid of the zeros.
Why is it that 1.1000 is the only thing returning multiplication with decimal places while other numbers such as 0.9000 and 1.2000 do not?

Best Answer

Welcome to the wonderful, exciting and often wacky world of floating point arithmetic!
>> 90*1.1-99
ans =
1.4211e-14
>>