# Cash Register -help

**URL:** <https://forum.freecodecamp.org/t/cash-register-help/397964>\
**Category:** General\
**Created:** [June 2, 2020, 9:16pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964 "2020-06-02T21:16:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlee232425](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mlee232425/32/134042_2.png) [@mlee232425](https://forum.freecodecamp.org/u/mlee232425)\
**Post date:** [June 2, 2020, 9:16pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964/1 "2020-06-02T21:16:42Z")

</div>

```auto
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?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 2, 2020, 9:26pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964/2 "2020-06-02T21:26:12Z")

</div>

hey, take a look at my answers in this other thread, see if they can help you, it seems you have the same issue (yep, only way):

> [@I'm stuck can someone help me!](http://forum.freecodecamp.org/t/im-stuck-can-someone-help-me/395430):
>
> Tell us what’s happening: for some reasons the code isn’t getting inside the for and while loops hence it returns the rest array unmodified (in the case of OPENED). i want to know why for while loops aren’t working like it should be Your code so far function checkCashRegister(price, cash, cid) { let rest = [['ONE HUNDRED', 0], ['TWENTY', 0], ['TEN', 0], ['FIVE', 0], ['ONE', 0], ['QUARTER', 0], ['DIME', 0], ['NICKEL', 0], ['PENNY', 0] ]; var curr…

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [June 2, 2020, 9:26pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964/3 "2020-06-02T21:26:49Z")

</div>

I recommend using an integer number of cents for everything. I know this is not what you want to hear, but with floating point values _roundoff will always happen_.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 2, 2020, 9:27pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964/4 "2020-06-02T21:27:39Z")

</div>

I moved your question to its own topic because you were asking a question related to your own code for a challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s). Also, it is advisable to use the Ask for Help button on the challenge, so it auto-populates with your current code and the challenge url.

Thank you.

* * *

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks are not single quotes.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:51pm UTC](https://forum.freecodecamp.org/t/cash-register-help/397964/5 "2021-06-01T18:51:30Z")

</div>


