Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中四舍五入到两位数来计时_Python_Python 3.x_Rounding - Fatal编程技术网

如何在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