Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just a silly little problem re: subtracting numbers

Status
Not open for further replies.

JoanieB

Programmer
Apr 17, 2001
57
US
In a recordset, I am totaling numbers:
NewFBal = 0
Select Case BHCFXind
Case True
NewFBal = BHCFX
If BBHFXind = True Then
NewFBal = (NewFBal - BBHFX)
If NewFBal = 0 Then
ReconStat = "Balanced"
DoCmd.RunSQL "INSERT INTO TblInput...
End if
End if
End Select
The numbers I am subtracting are equal (BOTH = 296697.67), so the net should be zero. Access says the NewFBal is
"-3...12-E"
{??The datatype for these numbers is Double, as that is the only way I can account for the potential 5 decimals??}

 
Make sure that the two numbers are identical. If they are doubles there is a good chance that they have aditional numbers after the intial two decimal places. Try rounding the numbers to 2 places b4 doing the math -

Round(numbera,2) - Round(numberb,2)

 
Round should work, however the more traditional approach is to compare the difference to a threshold value:
Replace the [i[Italicized][/i] statement w/ the Bolded one
NewFBal = (NewFBal - BBHFX)
If NewFBal = 0 Then
If NewFBal < 1.0e-4 Then
ReconStat = &quot;Balanced&quot;



MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Tried both, but neither solved the prob. Is there a reference I need to set for &quot;Round&quot; to be recognized by Access {97}?
Also, I need 5 decimal places in my numbers...
Thanks!
 
To Get/Display a specific # decimal Placesm use Format (val, FmtStr). Check HELP. The comparision of hte difference to a VALUE does work.

Please review the following:

MyVal = 296697.67
MyVal2 = 296697.67 + (-3.21e-7)
? MyVal = MyVal2
False
? Abs(MyVal - MyVal2) <= 1.0e-4
True
? Round(296697.67, 1)
296697.7

directly in Ms. A. ver 2K

So check how you set up YOUR situation, as the err does NOT appear to be in the advice you are receiving.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top