Why do my numbers not add up correctly in MATLAB?

When I add numbers together, and then compare the result to a number that I think is the correct result using "==" or the ISEQUAL function, the comparison returns as "false" or 0.
For example:
a = 0.1 + 0.1 +0.1;
b = 0.3;
a == b
ans =
0

 Accepted Answer

This behavior is related to floating-point arithmetic and the way numbers are represented in a computer. For more information on this subject, see the related Solution below.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!