Why 4.300000000001 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why 4.300000000001

i = 1.0 while i <= 12.0: print(i) i = i + 1.1

29th Aug 2019, 7:14 PM
Никита Якунин
Никита Якунин - avatar
3 Answers
+ 4
everything in the machine is stored in binary system for example x=5 will be 101 but some decimal numbers cannot be converted to binary system so it rounds it to the closest number
30th Aug 2019, 3:53 AM
ABADA S
ABADA S - avatar
+ 4
Because floating-point numbers are inaccurate and certain numbers can't be represented accurately. See the following two resources for info: https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate https://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm
30th Aug 2019, 4:02 AM
Lord Krishna
Lord Krishna - avatar
+ 3
When you use double and you add this multiple times it also has a little more than what you gave then it doesn't add 1.1 but 1.1000000000000001(just example)
29th Aug 2019, 7:36 PM
Eliya Ben Baruch
Eliya Ben Baruch - avatar