0
for _ in range(3):
sec=sec+1.3
round(sec)
print(sec)

I am working on a GUI/ML project and i ran the above simple snippet.I have to display the number in the GUI(pyqt5) but the output is all messed up.Here is the output that i got.(sec=0 at the start obviously)

  1. 1.3
  2. 2.6
  3. 3.9000000000000004

Questions:-

  1. Why is the output 3.9000000000000004??Why the anomaly??
  2. I have tried multiple ways to round up the number like ....but nothing works!! How can i round this upto 1/2 decimal places???
Raptor
  • 1
  • 1

1 Answers1

0

round(x) doesn't alter the value of x, it returns the rounded x

for _ in range(3):
    sec=sec+1.3
    sec_rounded = round(sec)
    print(sec_rounded)

Should do the trick