Very simple 'if' statement with == operator not working
Ältere Kommentare anzeigen
I have some very basic logic that is not working. It's a simple 'if' statement with an '==' operator. Please help.
Program:
%simple_script.m
clear all
A = 0.40;
B = 0.20;
C = 0.60;
D = A + B;
if C == D
disp('It worked.')
else
disp('It did not work.')
end
Command Window:
>> simple_script
It did not work.
>>
Akzeptierte Antwort
Weitere Antworten (1)
Geoff Hayes
am 22 Dez. 2017
1 Stimme
Graham - you are incorrectly trying to use equality with floating point numbers. See the Compare Floating-Point Numbers section of determine equality for an example of what to do.
1 Kommentar
Graham
am 22 Dez. 2017
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!