如何在python中四舍五入到两位数来计时
我正在写这个程序,我想把打印出来的时间四舍五入到十位如何在python中四舍五入到两位数来计时,python,python-3.x,rounding,Python,Python 3.x,Rounding,我正在写这个程序,我想把打印出来的时间四舍五入到十位 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) 我试着在打印前使用round(duration,2),但没有成功。我真的不知道该怎么做。
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)
我试着在打印前使用round(duration,2),但没有成功。我真的不知道该怎么做。可能有一个简单的答案,但我想不出来。谢谢 。这是该链接中提供的一个答案:
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))
如果是重复问题,请将问题标记为重复和/或注释,而不是添加一个回答说它是重复错误,无法对代表进行注释。谢谢。我每次运行它时,它都会给我2.00@arexplosible replice of