After comma precision tracking for if statement
Afficher commentaires plus anciens
I am having this number a=85.0093792283283 calculated in the code and I want to compare with another similar value something like this b=85.0093791964294. My question I just want to compare first 3 digit after the comma. Is there way to implement this in the example code?
if(a == b)
disp('Number are equal');
end
Réponses (1)
Alan Stevens
le 18 Mai 2021
Modifié(e) : Alan Stevens
le 19 Mai 2021
Here's one possibility
a=85.0093792283283;
b=85.0093791964294;
a = floor(a*10^3);
b = floor(b*10^3);
if a==b
disp('numbers are equal')
end
2 commentaires
Ibrahim A
le 18 Mai 2021
Jan
le 18 Mai 2021
@Ibrahim A: Yes, round is better for your problem.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!