# JavaScript Algorithms and Data Structures Projects: Cash Register/read-search can't handle

Help,bro.Can you tell me why […cid] show [[PENNY,-3.0878077872387166e-16]…] rather than [[“PENNY”, 0.5]…]

This’s my code:

``````function checkCashRegister(price, cash, cid) {
let base = [["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1.00], ["FIVE", 5.00], ["TEN", 10.00], ["TWENTY", 20.00], ["ONE HUNDRED", 100.00]].reverse();

let changeNum = cash - price;
let changedCid = [];
for (let i = 0; i < cid.length; i++) {
changedCid.push(cid[i]);
}
changedCid = changedCid.reverse();
let changedForUse = changedCid;

let change = [];
for (let i = 0; i < base.length; i++) {
change.push([base[i][0], 0.00]);
}

for (let i = 0; i < changedCid.length; i++) {
while (Math.floor(changeNum / base[i][1]) > 0 && changedCid[i][1] != 0) {
changedCid[i][1] -= base[i][1];
change[i][1] += base[i][1];
changeNum -= base[i][1];
changeNum = changeNum.toFixed(2);
}
}

if (changeNum > 0) {
return { status: "INSUFFICIENT_FUNDS", change: [] };
}

let resCid = 0;
for (let i = 0; i < changedCid.length; i++) {
resCid += changedCid[i][1];
}
resCid = Math.abs(resCid.toFixed(2));
let closedArr = [];
for(let i = 0;i<cid.length;i++){
closedArr.push(cid[i]);
}
if (changeNum == 0 && resCid == 0) {
console.log([...cid]);
return { status: "CLOSED", 'change': [...cid] };
}

// Here is your change, ma'am.

return { status: "OPEN", 'change': change.filter(x => { return x[1] != 0 }) };
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
``````

Thanks.

Making calculations with float numbers in JS can be funky. I would do a mathematical operation then round it to the nearest 2 decimals. This will result in a string so convert it back to a string. For ex.

`parseFloat((5.25 - 3.70).toFixed(2));`