Decimal places when multiplying by 1.1

3 views (last 30 days)
JohnJ
JohnJ on 11 Aug 2016
Edited: dpb on 12 Aug 2016
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?

Accepted Answer

dpb
dpb on 11 Aug 2016
Edited: dpb on 12 Aug 2016
Welcome to the wonderful, exciting and often wacky world of floating point arithmetic!
>> 90*1.1-99
ans =
1.4211e-14
>>

More Answers (0)

Community Treasure Hunt

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

Start Hunting!