Why is (2.24*10)-22.4 not equal to 0?

77 views (last 30 days)
I need to make some frequency responses where I made an frequency array according to the preferred numbers R40, fR40. Later I need to find the indices in another array which corresponds to the frequencies in fR40. The problem is that MatLab returns an empty array when I use find. I find out that the problem lies with some of numbers from the R40. Fx 2.12 and 2.24.
When typing (2.24*10)-22.4 in the command window yields 3.5527e-015.
Adding one decimal more fx 2.241 and 22.41 yields 0 as expected.
Can someone explain to me why it is that this happens?

Accepted Answer

James Tursa
James Tursa on 21 Jun 2012
>> num2strexact(0.3)
ans =
>> num2strexact(0.2)
ans =
>> num2strexact(0.1)
ans =
>> num2strexact(0.3-0.2-0.1)
ans =

More Answers (2)

the cyclist
the cyclist on 19 Jun 2012

Jan on 20 Jun 2012
This is a frequently asked question. All frequently asked questions appear frequently in this and other forums. They contain problems, which occur usually for nearly all beginners. Therefor it is recommended to study the FAQ for all software packages you use. In the case of Matlab, you find them here: http://matlab.wikia.com/wiki/FAQ, and for your question Why is 0.3 - 0.2 - 0.1 ~= 0 .
This message is implicitely given in the answer of the cyclist. Anyhow, I could not resist to suggest reading the complete FAQ. Actually I'd prefer to add a checkmark in the login dialog of this forum, that the FAQ are read before a question is asked, because this would reduce the number of repeated questions.
Jan on 21 Jun 2012
Let me vote for Walter's survey.

Sign in to comment.



Community Treasure Hunt

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

Start Hunting!