i am having trouble figuring out why my timer is not reaching zero when i run it. I am trying to get the window to close when a=0 but a keeping decreasing to negative digits why please? This is my codes
def close_timer(self):
global a
a = float(a - 0.1)
self.labeltext.set(str(("%.1f" % (a))))
a = float(a)
print a
print (a == 0)
if a == 0:
self.canvas.after(100)
self.root.destroy()
self.root.after(100,self.close_timer)
Floating point number math is generally inaccurate – you can’t represent a decimal
0.1in binary floating points exactly, therefore you’ll never reach0:Use
if abs(a) < 0.000001:or something similar.