Hello, I'm on Visual Basic .NET 2003.
Before I had to format my PC a while back, I had this VB.NET program that was simple enough: Input a USD amount into a text box, click the button, and watch it divide the total into $20's, $10's, etc. all the way down to the pennies. It was never all that accurate, so today I decided to re-do the program, and shoot for 100% accuracy.
It took me a grand total of an hour and a half to write code to error-check the input textbox, then Do Until loop the total until I had the figures listed. (Basically, the actual code to sort out dollar amounts was nothing but Do loops the whole way down. I can't remember how I did it before, but it wasn't this, nor did it have any accuracy as I said.)
After that, I wanted to extrapolate: What if someone didn't
want, for example, $20 bills listed? So I wrote a not-so-elaborate method of allowing the user to choose each denomintion to Include it or Exclude it.
Of course, this meant that there might be a remainder, due to the small change being excluded, or if the user put in three decimal places. So, I put in a system to display this remainder. Easy, right? Yes.
BUT...
If the user inputs a number with three decimal places, and that last decimal
happens to be a 1, I get kooky remainders.
Here is a thumbnail (click for larger version) of the program in progress with no remainders. Everything works properly. (The progress bar was for debugging purposes, to see just where in the program I'd have a crash. I left it in as a "feature", but it's really instantaneous unless I'm dealing with large figures.)
Here's the same program, run with a three-digit decimal which caused a remainder. Perfectly normal.
Next, a three-digit decimal with 1 as the third digit. The remainder
should be 0.009, but...
Attached is a text file with the source code, sans the Form Generated code. I'm hoping it's obvious where the flaw is, but I can't find it. :-/