So I've got a function that sums a set of numbers which are to 1 decimal place, and the resultant number is to something like 18 decimal places.
The set of data is:
0.7
0.7
0.2
The function that loops through the data and adds them is this:
def test_function( ind ):
utility=0
for i in range(N):
utility = utility + ind.gene[i]
print(utility)
return utility
When it adds 0.7 and 0.7, it gets 1.4. This is fine. But then it adds 0.2 to the 1.4 and gets 1.5999999999999999.
Why does this happen?