Jun-12-2020, 07:32 AM
I appreciate your reply to my problem. Your code and background are very useful for me.
Although I am still puzzled with "format(100*1e-6, ".15e") -->9.999999999999999e-05"...
Although I am still puzzled with "format(100*1e-6, ".15e") -->9.999999999999999e-05"...
(Jun-11-2020, 08:19 AM)bowlofred Wrote: Many numbers cannot be exactly represented in the computer's floating point representation. So it stores as close as it can get.
You might be better off using format to display the number rounded to some decimal points.
>>> format(100*1e-6, "f") '0.000100' >>> format(100*1e-6, ".17f") '0.00010000000000000' >>> format(100*1e-6, ".20f") '0.00009999999999999999'or if you prefer exponential format...
>>> format(100*1e-6, "e") '1.000000e-04' >>> format(100*1e-6, ".11e") '1.00000000000e-04' >>> format(100*1e-6, ".15e") '9.999999999999999e-05'For background, https://docs.python.org/3.8/tutorial/floatingpoint.html