+ 4

# Why

i.e. when i write i=i+0.2 instead of I=I+1 why results like this; 1 1.2 1.4 1.7999999999 1.9999999999 2.1999999999 anyone know why?

5th Apr 2017, 8:22 PM
serkan
+ 7
floats/doubles use the floating point number system, and are not 100% accurate.
5th Apr 2017, 8:32 PM
Rrestoring faith
+ 2
Mashine code always a bit incorrect,you can google about it :) Usualy it's not a problem,but just in case you should keep it in mind :) If it needed you can use functions\methods(or what pythin had it this case idk :D) which will return right result...
5th Apr 2017, 8:30 PM
Rose Sevenyears
0
thank you
5th Apr 2017, 8:31 PM
serkan
0
Most machines are calculating with binary fractions instead of decimal fractions. For example: Decimal 0.2 is just short for the fraction decimal 2/10. Decimal 2/10 is binary 10/1010 If you try to calculate binary 10/1010 you get 0.001100110011... It's like calculating the result of 1/3 in decimal which is 0.3333333.... Binary fraction with infinte decimal places are often corrected to a resonable number of decimal places for output.That's why we usually do not recognize this issue.
7th Apr 2017, 11:33 AM
Dirk