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

change calculation #2

Open
wobweger opened this issue Oct 17, 2021 · 1 comment
Open

change calculation #2

wobweger opened this issue Oct 17, 2021 · 1 comment

Comments

@wobweger
Copy link

I dought calculation performed is correct:

127.0.0.1:5000/change/1/15

delivers

[
  {
    "4": "quaters",
  },
  {
    "1": "dimes",
  },
  {
    "4": "pennis",
  }
]

in my opinion, I'm 1 penny short.
should result not be

[
  {
    "4": "quaters",
  },
  {
    "1": "dimes",
  },
  {
    "1": "nickles",
  }
]

? which I get passing in 127.0.0.1:5000/change/1/16.

@vcarmen
Copy link

vcarmen commented Oct 29, 2021

@wobweger, I got the same result, the problem was not rounding and just taking the int value, in the first mod, changing it to the next code returns the correct value

num, rem = divmod(int(round(amount*100)), coin)

{"amount": "1.15"}

[ { "4": "quarters" }, { "1": "dimes" }, { "1": "nickels" } ]

updated line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants