if statement different answer when input variable vs number
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I do not understand why the if statement here produces different results. In one statement, I use the variable names, and in the other I substitute the variable values for the names. Each if statement should yield 'true' because no values are changed.
>> time_end
time_end =
30.0000
>> time_met_end
time_met_end =
30
>> if time_end>time_met_end
disp('true')
end
true
>> if 30.0000 > 30
disp('true')
end
>>
>>
0 commentaires
Réponse acceptée
dpb
le 10 Fév 2017
See the FAQ Why is 0.3-0.2-0.1 not equal to zero? for background in "why". The variable containing what is printed at the command line as 30.0000 isn't quite that, exactly. That the trailing zeros after the decimal are printed is the giveaway that it isn't integer-valued.
Try
time_end-30
to see the remainder for
fprintf('%.15e',time_end)
to display the value with all the digits shown.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!