0

I am writing this program and I want to round the time that gets printed off to the tens place.

from timeit import default_timer
        start= default_timer()
#This is where i have a bunch of other code that isn't relavant
duration = default_timer()-start
print (duration)

I tried to use round(duration, 2) before I printed it and that didn't work. I just don't really know how to round it. There's probably a simple answer but I couldn't figure it out. Thanks!!

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • 4
    Possible duplicate of [Limiting floats to two decimal points](https://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points) – Arex Aug 29 '17 at 23:50

1 Answers1

-2

Duplicate of this question. This is one answer provided in that link:

from timeit import default_timer
import time

start= default_timer()
time.sleep(2)  # Insert your code here.
duration = default_timer()-start
print("{0:.2f}".format(duration))
Arex
  • 52
  • 5