Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

# Exact Change Problem Issue

See original GitHub issue

#### Challenge Name

https://www.freecodecamp.com/challenges/exact-change

#### Issue Description

I had problem with this problem due to inaccurate calculations while working with “0.01” value. Sometimes returning value of calculation had wrong value after 7 or 8 decimal places (for example 1.01 - 0.01 = 0.999999996). Did anyone else had similar problem? I managed to solve it but still took me a lot of time to do it due to this issue that shouldn’t happen… Anyone have any idea why it is so. My opinion is that it is due to way that js saves integer and float values…

#### Browser Information

• Browser Name, Version: Google Chrome, 52.0.2743.82 (64-bit)
• Operating System: Linux Ubuntu 16.04
• Mobile, Desktop, or Tablet: Laptop

``````
``````

### Issue Analytics

• State:
• Created 7 years ago

4reactions
BKinahancommented, Aug 4, 2016

Hi, @FatKoala. You can read all about floating point arithmetic (and good ways to handle it) here and other places online.

And a fun fact: JavaScript doesn’t make a type distinction between floats and integers. `1` and `1.00000` are the same number in JS (though this isn’t strictly the cause of the floating point precision errors you experienced).

It might be worthwhile to include a resource about floating point arithmetic (though not necessarily the one I linked to above) in the Helpful Links of this challenge as it is probably the first one which requires users to understand the precision issues it raises.

2reactions

Yeah this is a very interesting topic and should be broached IMHO.

In JavaScript there is just on numeric Data type that is `number` and it’s usually a 64 bit floating point (considering how Browsers (JS Engines to be precise) are implementing them).

Let’s tag this as Help wanted for some one in the community to link up a good resource. I’ll try and look up as well, but yeah it’s better if it comes from someone who perhaps is a Language expert.

#### Top Results From Across the Web

Exact Solution for “Exact Change” - freeCodeCamp
The method it uses is to use the highest denomination and go down until it reaches the goal or the lowest denomination. It...
Exact Change Algorithm - python - Stack Overflow
The problem your current algorithm has is that it only ever attempts to recurse once. ... There's another issue with your code though....
Change-making problem - Wikipedia
The change-making problem addresses the question of finding the minimum number of coins (of certain denominations) that add up to a given amount...
Algorithm Exact Change inaccurate output! #9657 - GitHub
The only reason I can see that cash paid should be more than double (let alone more than six times) the price would...
Problem - 1620D - Codeforces
For each test case, print one integer — the minimum number of coins you need to buy one bag of any flavor you'll...

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free