如何在Python中移动小数位?

发布于 2021-01-29 14:56:57

我目前正在使用以下内容两次计算差异。出局非常快,因此无论如何我都不需要显示小时和分钟,它们仅是0.00。我实际上如何在Python中移动小数位?

def time_deltas(infile): 
    entries = (line.split() for line in open(INFILE, "r")) 
    ts = {}  
    for e in entries: 
        if " ".join(e[2:5]) == "OuchMsg out: [O]": 
            ts[e[8]] = e[0]    
        elif " ".join(e[2:5]) == "OuchMsg in: [A]":    
            in_ts, ref_id = e[0], e[7] 
            out_ts = ts.pop(ref_id, None) 
            yield (float(out_ts),ref_id[1:-1], "%.10f"%(float(in_ts) - float(out_ts)))

INFILE = 'C:/Users/kdalton/Documents/Minifile.txt'
print list(time_deltas(INFILE))
关注者
0
被浏览
73
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    与数学相同

    a = 0.01;
    a *= 10; // shifts decimal place right
    a /= 10.; // shifts decimal place left
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看