I'm wondering how and why the results are True, False?! 7.8 > 5 , 10 < 10.0000000000000000001 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I'm wondering how and why the results are True, False?! 7.8 > 5 , 10 < 10.0000000000000000001

This is a very very simple python script

29th Sep 2017, 5:12 AM
reza
reza - avatar
8 Answers
+ 3
What emoji is it? I can't see
29th Sep 2017, 5:19 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
wondering, confusing
29th Sep 2017, 5:22 AM
reza
reza - avatar
+ 2
Actually 10<10.00000000000000000001 will return False due to the limitations of floating point numbers
29th Sep 2017, 5:14 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
10.00...001 approximates to 10.0
29th Sep 2017, 5:15 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
so how can I fix such problems?
29th Sep 2017, 5:16 AM
reza
reza - avatar
+ 2
Floating point numbers have ~6dps of maximum accuracy
29th Sep 2017, 5:18 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
🙄🤐
29th Sep 2017, 5:18 AM
reza
reza - avatar
+ 1
Cannot
29th Sep 2017, 5:18 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar