+ 5
Python: 3 * 0.4 = 1.2000000000000002
Why is multiplying 3 or 13 or 23 etc. with floats giving such wierd results?
5 Respuestas
+ 7
That's because computers handle numbers in binary.
You can't convert 1.2 into binary.
It would be 1.00110011001100110011... (continues infinitely) computer needs to round that, and the result that is converted back to decimal would be inaccurate.
+ 4
It's called floating point arithmetic error, it is not related to python only, but to most (all?) programming languages. The reason is because computer cannot represent floats with high precision, therefore sometimes there can be an error while calculating them. For example if you try:
0.1+0.1+0.1 == 0.3
This will return False, so it can really affect the program if you don't know about it.
You can read more about it here:
http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm
+ 2
https://m.youtube.com/watch?v=wPBjd-vb9eI
+ 1
Ярослав Вернигора (Yaroslav Vernigora) Iam watching the video, great link 👌
0
sorry, but I didn't watch this video. I found it in a search engine just now. really great?