I am going to strongly suggest you do NOT use real numbers for financial

calculations. I have written a good many payroll systems, and I can assure

you that is not even close to even being possible to consider writing any

computer application where you use single, or double value numbers for

financial calculations. Computers can only approximate represent real

values. As a result, all kinds of round problems will occur.

Try the following code in a module, and not the output:

Dim s As Single

Dim i As Integer

For i = 1 To 10

s = s + 0.01

Next i

Debug.Print s

Debug.Print s = 0.1

The above actaully results in:

9.999999E-02

False

Wow, look at the above. We have only added a number 10 times, and look at

the huge rounding errors you got. Note how the comparison of "s = .1"

results in return a false value. Further, note how we do not get a expected

answer of .1

The reason for the above is that computers use "0" and "1" to represent a

real number. In the above case, the computer has to try and represent

1/100th. You can't do that with a real number in binary. The solution is to

NOT use real numbers in your calculations. You should use integers, as they

do NOT suffer this routing problem. As it turns out, we have a scaled

integer called "currency". It is allows up to 4 decimal places. However, it

is really a fake real number, and in fact is stored as a integer with a

"scale" of 4 decimal places.

So, lets try the above code with a currency type:

Dim s As Currency

Dim i As Integer

For i = 1 To 10

s = s + 0.01

Next i

Debug.Print s

Debug.Print s = 0.1

0.1

True

As you can see, there is no rounding problems. This is also how desktop

calculators avoid the rounding problem also. However, in the computing

world, the above is a daily problem we have had to deal with for the last 50

years (This is also one of the first things you are taught in computing

science). That is why I suggest you use currency type.

--

Albert D. Kallal (MVP)

Edmonton, Alberta Canada

ka****@msn.com http://www.attcanada.net/~kallal.msn