我的列表包含转换为float的值:
time = [1472120400.107, 1472120399.999, 1472120399.334, 1472120397.633,
1472120397.261, 1472120394.328, 1472120393.762, 1472120393.737]
但是当我执行time[0]
时,该值会四舍五入到1472120400.11
之类的2位小数。在访问单个列表值时,如何保留原始值(精确计算最多3个小数位?)
我的代码:
for line in line_collect :
a = re.search(rx1,line)
time = a.group()
newlst.append(float(time))
print newlst
print newlst[0]
输出:
[1472120400.107,1472120399.999,1472120399.334,1472120397.633, 1472120397.261,1472120394.328,1472120393.762,1472120393.737]
1472120400.11
答案 0 :(得分:4)
列表本身没有舍入值。这是显示四舍五入的默认“打印”:
>>> time = [1472120400.107, 1472120399.999, 1472120399.334, 1472120397.633,
1472120397.261, 1472120394.328, 1472120393.762, 1472120393.737]
>>> time[0]
1472120400.107
>>> print time[0]
1472120400.11
您可以通过打印repr来获得完整的精确输出:
>>> print repr(time[0])
1472120400.107