解决使用round函数后,某些值小数位没有保留对应位数

直接上round函数例子,虽然不太懂,问题已经解决
#1.round函数前不加float
x = [i for i in range(569, 602)]
print(x)
y=[]
for i in x:
y.append(round((6.3*np.sin(0.0175*i-6.32)+17.53),1))#注意,没有添加float
print(u"正弦曲线预测值为:")
print(y)
#输出为[14.5, 14.4, 14.300000000000001, 14.199999999999999, 14.199999999999999, 14.1, 14.0, 13.9,...

#1.round函数前加float
x = [i for i in range(569, 602)]
print(x)
y=[]
for i in x:
   y.append(round(float(6.3*np.sin(0.0175*i-6.32)+17.53),1))#注意,添加了float
print(u"正弦曲线预测值为:")
print(y)
#输出为[14.5, 14.4, 14.3, 14.2, 14.2, 14.1, 14.0, 13.9, 13.8, 13.7, 13.6, 13.5, 13.4,...





上一篇:内置函数_round


下一篇:【codeforces题解】 Codeforces Round #709 (Div. 2, based on Technocup 2021 Final Round)