Javascript Cash Register Problem

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?

its a complicated issue(and im not knowledgeable to explain it), but you should check the offered tips/solution on the challenge. Its decimal values that cause calculation errors and in order not to encounter such, you should multiply numbers by 100(for example), so they dont go bellow the decimal point.

It’s a Javascript thing, it doesn’t round up or down numbers unless specified. If you want to use only the last 2 decimals, you can append the method .toFixed(2).
For example, if you place it in the console.log, it’d be (total.toFixed(2)).
Note that it will return a string (although it’s a Number method), so if you need it, you’ll need to convert it to number again.

I suggest this video, it also briefly mention how it is dealt with from banks and similar