0

I'm creating a basic program to break a user-inputted amount of money down into the smallest number of bills and coins, and I'm running into an issue with float variables. Both when using scanf and when giving the variable an amount while defining it, I've run into an issue where the float is randomly changed. For example, I'll define amount as 200.53, then when I reprint the variable to check, it prints out 200.529999.

I'm very new to C, so there may be a simple solution, but I've tried, rounding, flooring, and other solutions I've found online to no avail. Even after I round amount or floor it using amount = round(amount * 100) / 100, it still prints 200.529999. Thanks! Here is an image of my code and the output

Thanks!

  • [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – 0stone0 Jan 24 '22 at 15:30
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Sam Mason Jan 26 '22 at 19:22

0 Answers0