function checkCashRegister(price, cash, cid) {
let change = cash-price;
let unit = [['ONE HUNDRED', 0], ['TWENTY', 0] , ['TEN', 0], ['FIVE', 0], ['DOLLAR', 0], ['QUARTER', 0], ['DIME', 0], ['NICKEL', 0], ['PENNY', 0]]
let value = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01]
let cidValues = []
let numbers = []
let sum = 0
let open = []
let closed = []
for (var i = 0; i < cid.length; i++){
sum = sum + cid[i][1]
cidValues.unshift(cid[i][1]) // listing the amount of each unit
} // finding sum of cash in drawer
for (var k = 0; k < value.length; k++){
numbers.push(Math.round(cidValues[k]/value[k]))
}
console.log(value)
for(let j = 0; j < value.length; j++){ // LOOPING THRU TO GET TOTALS
let total = 0
while(change > 0 && change >= value[j] && cidValues[j] > 0){
Math.ceil(change -= value[j])
Math.ceil(total += value[j])
Math.ceil(cidValues[j] -= value[j])
}
unit[j][1] = total
console.log(unit)
console.log(change)
}
}
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]]);
My results are off by just 0.01 cents for the penny array. Does anyone know how I can round up decimals without just turning them into integers?