-
[RESOLVED] Math problem
I getting erroneous results from a simple add and subtract loop. I'm sure it's something simple, but I don't see it.
On the form is an array of textboxes and a label
Code:
private sub xxxxxxxx
Dim Tot As Double
Dim X As Integer
Tot = 0
For X = 1 To 8
If TxtFld(X).Text <> "" Then
If X <= 3 Then
Tot = Tot + CDbl(TxtFld(X).Text)
Else
Tot = Tot - CDbl(TxtFld(X).Text)
End If
End If
Next
LblBal.Caption = CStr(Tot)
end sub
if txtfld(1) = 10
& txtlfd(4) = 5
& txtfld(6) = 5.1
then it should be
10 - 5 - 5.1 = -0.1
but I get -9.99999 ?????
what gives?
-RT
The actual answer given by vb is -9.99999999999943E-02
-
Re: Math problem
There are numerous posts on this site regarding the Double variable type and how it returns values. You can search them for more education/information. In the mean time, if you are only concerned with a max of 4 decimal places, recommend using Currency vs Double and CCur vs CDbl