Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact Change Problem Issue #10074

Closed
FatKoala opened this issue Aug 4, 2016 · 5 comments
Closed

Exact Change Problem Issue #10074

FatKoala opened this issue Aug 4, 2016 · 5 comments
Labels
help wanted Open for all. You do not need permission to work on these.

Comments

@FatKoala
Copy link

FatKoala commented Aug 4, 2016

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

Your Code

Screenshot

@BKinahan
Copy link
Contributor

BKinahan commented 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.

\cc @FreeCodeCamp/issue-moderators for feedback on adding such a link (and which link to add)

@raisedadead
Copy link
Member

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.

@raisedadead raisedadead added the help wanted Open for all. You do not need permission to work on these. label Aug 4, 2016
@FatKoala
Copy link
Author

FatKoala commented Aug 4, 2016

Thanks for the link, it was helpful... got really frustrated about problem while I was coding... now it has sense... I agree that it should be linked somewhere or explained earlier that those things happen...

@dhcodes
Copy link
Contributor

dhcodes commented Aug 10, 2016

I poked around a bit and @BKinahan's link seems to be at least as good if not better than most and seems to be a straight-forward site. I vote we use his link. I'm happy to do the PR unless someone else wants to.

@raisedadead
Copy link
Member

@dhcodes please go ahead, 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open for all. You do not need permission to work on these.
Projects
None yet
Development

No branches or pull requests

4 participants