I have a variable of type Double that is not always the value that it should be, and I can't figure out why. Here's some of the code.
(There is other code that assigns the value to TotalsInArray, but it's complicated and I don't think it's the problem, so I did not include it here.)
TotalNotAssigned, TotalOnForm, and TotalsInArray are all of type Double. (They are meant to hold dollar values with two decimals.)
I added those three variables to the watch window so I could see what they were while I was stepping through my code.
Sometimes TotalNotAssigned is not what it should be. For instance, in the test I was just doing, TotalOnForm and TotalsInArray were both equal to the same thing: 237.11
However, TotalNotAssigned does not equal zero when that last line of code is run. Instead, it is equal to 2.8421709430404E-14. I do not understand why this is happening. Any ideas?
Here's a screenshot of the Watch window, so you can see what I mean.
https://postimg.cc/BLYFwPn9
Code:
TotalOnForm = Val(Replace(.Range("AC41").Value, ",", ""))
TotalNotAssigned = TotalOnForm - TotalsInArray
(There is other code that assigns the value to TotalsInArray, but it's complicated and I don't think it's the problem, so I did not include it here.)
TotalNotAssigned, TotalOnForm, and TotalsInArray are all of type Double. (They are meant to hold dollar values with two decimals.)
I added those three variables to the watch window so I could see what they were while I was stepping through my code.
Sometimes TotalNotAssigned is not what it should be. For instance, in the test I was just doing, TotalOnForm and TotalsInArray were both equal to the same thing: 237.11
However, TotalNotAssigned does not equal zero when that last line of code is run. Instead, it is equal to 2.8421709430404E-14. I do not understand why this is happening. Any ideas?
Here's a screenshot of the Watch window, so you can see what I mean.
https://postimg.cc/BLYFwPn9