I have an interval range generated by python numpy. The values are as expected but when the array is transform into list, the values are not same as in array.
numpy.linspace(0.3,0.7,5)
array([ 0.3, 0.4, 0.5, 0.6, 0.7])
numpy.linspace(0.3,0.7,5).tolist()
[0.3, 0.39999999999999997, 0.5, 0.6, 0.7]
list(numpy.linspace(0.3,0.7,5))
[0.29999999999999999,0.39999999999999997,0.5,0.59999999999999998,
0.69999999999999996]
Why numpy behaves like this? Is there anyway to keep the values in the list the same as array without using another loop for rounding the values in the list?