将指数转换为浮动时间时钟()

2024-04-24 11:58:04 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

import time
t0=time.clock()
t1=time.clock()
time_difference = t1-t0
print time_difference

输出是

^{pr2}$

我想把t1-t0的值赋给浮点格式的时间差,小数点后有两位数字,我该怎么做


Tags: import密码time格式数字浮点t1print
2条回答

指数转换为浮点的最简单方法是

e_variable = 4.3e-05 

convert_to_float = str('%.08f' % e_variable)

print convert_to_float

如果要打印值,可以使用格式化输出。这将在点后打印两个十进制数字的浮点值:print "%.2f" % time_difference。在

如果希望将time_difference更新为两位数的浮点值,可以使用round函数(请参见https://docs.python.org/2/library/functions.html#round):time_difference = round(time_difference, 2)。在

相关问题 更多 >