I encountered the following line of (C++) code today, along with a few more like it:
totalcost = rnd((totalcost += cost), 2);
Now, as far as I can see, there's a few things wrong:
- The += is pointless - it should just be a +
- rnd() does not return a random number like in every other program/language I've seen. It rounds the 1st argument to the number of decimal places specified by the 2nd.
- totalcost and cost are double-precision floating point numbers. Ever rounded a floating point number and got the expected result? rnd() actually converts the double to a decimal, rounds it, then converts it back to a double.
Fixing bugs in a VB program is like playing whack-a-mole.