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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Subtracting Identical Integers Incorrectly

Status
Not open for further replies.

JoanieB

Programmer
Apr 17, 2001
57
US
The code I have is lengthy, so maybe we can solve this problem without?

In my code:

ALL variables are declared as double for use with the entire module.

ALL variables are initialized to zero before the math is being done.

I scroll thru a recordset, adding like records together.

At the end, I subtract two of the variables from each other.
BEFORE I do, I check the value of the variables.
In some (but not all) instances where the two values being subtracted are identical,
the answer is not zero. I get 9.09102349E-013 or something.

WHY?!?!?!?
 
JoanieB,

9.09102349E-013 is actually

.000000000000909102349

So, it may look as though the numbers are identical, but somewhere along the line there is a difference of just that much. I don't know how you're checking the numbers, but unless what you're viewing them with is rather large, this difference won't show up.

you could, at the end of your routine, put something to the effect of:

If [ResultingNumber] < .00000001 then
[ResultingNumber] = Int([ResultingNumber])
End If

This would give you your 0 in a case like you mentioned.

The only way to be absolutely certain where the discrepancy lies would be to step through your code with a calculator and check for yourself. Which in all fairness wouldn't work either because a calculator won't give you to the -13th power...

Hope this helps,
Kyle ::)
 
Hmmmmmmmmmmmmmmmmm,

Are you SURE the values are INTEGERS?

At the top of the post, you SAY - ... all are declared as double ... -

So, if the Vars are DELCARED as DOUBLE, why would you THINK the are INTEGERS? Ms. A (obviously) thinks they are NOT integers, so you need a REALLY, REALLY, REALLY good argument to convince &quot;HER&quot; that the vars hold only INTEGERS!

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
It is the nature of the mantisa in a floating point number not to be zero. This should not be a problem, if you want a large integer number use the 'Long' in Access.
 
Thanks for all of your suggestions! Kyle - you had the answer I needed. It was so easy to see; but it always IS once you've heard the answer, right?
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top