function checkCashRegister(price, cash, cid) {
let change = cash - price;
let total = 0;
for (let i in cid) {
console.log(total);
total = total + cid[i][1];
}
console.log(total);
}
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
Something weird is happening when I add the total of the values. This is what the console returns for the values of total.
0
1.01
3.0599999999999996
6.16
10.41
100.41
155.41
175.41
235.41
335.40999999999997
Why are there random non-terminating decimals for the second and last iterations?