# Cash Register ----Question about the value

**URL:** <https://forum.freecodecamp.org/t/cash-register-question-about-the-value/212158>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [July 27, 2018, 3:21am UTC](https://forum.freecodecamp.org/t/cash-register-question-about-the-value/212158 "2018-07-27T03:21:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![z765089123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/z765089123/32/95240_2.png) [@z765089123](https://forum.freecodecamp.org/u/z765089123)\
**Post date:** [July 27, 2018, 3:21am UTC](https://forum.freecodecamp.org/t/cash-register-question-about-the-value/212158/1 "2018-07-27T03:21:02Z")

</div>

**Tell us what’s happening:**  
The value of \*_nchange = nchange-(n-1)value[i]_ seems like to be ‘36.74’ after the first subtraction but it returns 36.739999999999995 .

 ![33](https://global.discourse-cdn.com/freecodecamp/original/3X/2/0/2024fd734ed76924a4be141e72b35d0aa0ddc5f9.jpg)

**Your code so far**

```js

function checkCashRegister(price, cash, cid) {
  var change=[];
  var value = [0.01,0.05,0.1,0.25,1,5,10,20,100];
  var nchange= cash - price; //The left amount of change
  console.log(nchange);
  for(let i=value.length-1;i>=0;i--){

	  for(var n=1;nchange -value[i]*n>=0;n++){ // n-1 = The number of Currency Unit
	  	if(value[i]*n>cid[i][1]){
	  		break;
	  	}
	  }

	  if(n-1>0){
	  	console.log(nchange);
	  	console.log((n-1)*value[i]);
	  	nchange = nchange-(n-1)*value[i];
	  	console.log(nchange);
	  	change.unshift([cid[i][0],(n-1)*value[i]]);
	  }

  }
  console.log(nchange);
  console.log(change);
  return change;
}

//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]]);
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 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36`.

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![zapcannon99](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zapcannon99/32/94297_2.png) [@zapcannon99](https://forum.freecodecamp.org/u/zapcannon99)\
**Post date:** [July 27, 2018, 3:51am UTC](https://forum.freecodecamp.org/t/cash-register-question-about-the-value/212158/2 "2018-07-27T03:51:13Z")

</div>

You’ve discovered one of the annoying things about javascript, the lack of floating point precision.

I had to round to the nearest cent every calculation to make sure that it did what I wanted it to do.

```auto
function strip(x) {
  return Number.parseFloat(x).toFixed(2);
}

```

---

<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:** [February 2, 2021, 11:37am UTC](https://forum.freecodecamp.org/t/cash-register-question-about-the-value/212158/3 "2021-02-02T11:37:35Z")

</div>

Closed on February 2, 2021, 11:37am UTC


