Python Forum

Full Version: Python math error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I'm new at python but seen a math error. (Python 3.6.4)
Please simply run the code below and see the results.
Also you can try with different numbers...

a=86200
while a>0.0001:
    print(a)
    a/=10

a=0.000862
while a<100000:
    print(a)
    a*=10
I got these results;


Output:
86200 8620.0 862.0 86.2 8.620000000000001 0.8620000000000001 0.08620000000000001 0.008620000000000001 0.0008620000000000001 0.000862 0.008620000000000001 0.08620000000000001 0.8620000000000001 8.620000000000001 86.20000000000002 862.0000000000002 8620.000000000002 86200.00000000001
What can you say me about that error???
a simple addition will do, 0.00000000000000001+1, the output is 1.0 .(python 2.7)
(Feb-11-2018, 08:52 AM)buran Wrote: [ -> ]we can tell you that it's not an error http://floating-point-gui.de/ https://en.wikipedia.org/wiki/Floating-point_arithmetic https://docs.oracle.com/cd/E19957-01/806...dberg.html

Dear Buran, thank you for your informations...