一些浮点值的小数位数更多

时间:2019-05-17 06:46:11

标签: python

我正在编写一个小的代码来生成介于0和1.01之间的101个十进制值,并将其与csv文件中可用的Marcum Q函数值相关联

import numpy as np


with open('qfunction_val.csv','rt')as f:
  data = csv.reader(f)
  for row in data:
        print(row)
        p.append(row)
r=np.arange(0,1.01,0.01)


for i in range(np.size((r))):
    q.append((p[0][i],r[i]))

运行代码时,输​​出如下:

 ...
 ('0.4676987991145082', 0.32),
 ('0.4399131656732337', 0.33),
 ('0.4124631294414047', 0.34),
 ('0.3853204664075676', 0.35000000000000003),
 ('0.3584587932511938', 0.36),
 ('0.3318533464368166', 0.37),
 ('0.3054807880993974', 0.38),
 ('0.2793190344474542', 0.39),
 ('0.2533471031357998', 0.4),
 ('0.2275449766411493', 0.41000000000000003),
 ('0.2018934791418509', 0.42),
 ('0.1763741647808613', 0.43),
 ('0.1509692154967773', 0.44),
 ('0.125661346855074', 0.45),
 ('0.1004337205114698', 0.46),
 ('0.07526986209982976', 0.47000000000000003),
 ('0.05015358346473367', 0.48),
 ('0.02506890825871106', 0.49),
 ...

为什么仅对于某些值,它的小数位就比另一些小。

我该如何避免呢?

0 个答案:

没有答案