I have created the next code, where I have an ArrayList of Doubles "solution". I want to multiply all the doubles inside this ArrayList. For example, if the solution is [0.9,0.5,0.2], the code returns "0.09000000000000001" and not the real result of 1*0.9*0.5*0.2 = 0.09
double actualCost = 1;
for(int j = 0; j < solution.size(); j++) {
actualCost *= solution.get(j);
}
return actualCost;
I don't know why I have this problem, if someone can help me to fix it I'll really appreciate it.
Thanks in advance.
(sorry for my english lvl)