I have something weird going on while adding 0.1 to another number in a loop.
function updateLoop() {
for (var key in resources) {
if (resources.hasOwnProperty(key)) { // Key is "Population" here.
// Add income to stock.
resources[key][1] += resources[key][0];
document.getElementById(key).innerHTML = resources[key][1];
}
}
setTimeout(updateLoop, 3000);
}
Now for some reason instead of adding 0.1 it sometimes adds 0.1000000000000001
Inside the resources
object:
Population: Array[2]
0: 0.1
1: 1.2000000000000002
Anyone knows why this happens? Can I fix it?