My issue should be well logged to the console for you to see. It appears that as I reach the final penny needed to remove from the changeOwed variable, the value goes from being 0.01 to 0.009999999999994869. Thus breaking my code. Is this right? Why is this happening? What’s the best way to fix this? Thanks.
JavaScript Algorithms and Data Structures Projects: Cash Register
Well I got it to pass all the tests by just removing that test for strict equality between changeGiven and changeOwed. This is what I got FCC to accept:
Floating point math is only as precise as the number of bits allocated allows (64 bits in javascript). So you get some rounding that looks like this. You will want to apply the method toFixed(2) to make the output fixed to include 2 digits after the decimal point. No more, no less. petern’s example uses this.