Decimals correction

Hi,

I solved the cash register using the below code but I had to add a correction as last Penny is not complete, is there any way I can prevent this?


function checkCashRegister(price, cash, cid) {
var change=cash-price;
var coinsVal=[["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
var total=getTotal(cid);
coinsVal=coinsVal.filter(a=>a[1]<=change);
var mon4Change=cid.filter((a,b)=>(a[0]==coinsVal.map(a=>a[0])[b]));
if(change==total){
    return {status: "CLOSED", change:cid};
  }
if(change>getTotal(mon4Change)){
  return {status:"INSUFFICIENT_FUNDS", change:[]};   
}
coinsVal.reverse();
var mon=[];
var back=mon4Change.reverse().forEach(function (a,b){
  if(change>a[1]&&change>coinsVal[b][1]){
    change-=a[1];
    mon.push([coinsVal[b][0],a[1]])
  }else if(change>coinsVal[b][1]){
    var canTake=coinsVal[b][1]*Math.floor(change/coinsVal[b][1]);
    change-=canTake;
    if(0.01>change&&change!=0){//correction for decimals
      mon.push([coinsVal[b][0],canTake+0.01]);        
    }else{
      mon.push([coinsVal[b][0],canTake]);
    }
  }
});
return {status:"OPEN", change:mon};
}
function getTotal(arr){
return arr.map((a)=>a[1]).reduce((a,b)=>a+b);
}

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36.

Challenge: Cash Register

Link to the challenge:

I recommend using an integer number of cents instead of a decimal number of dollars.