VB Floating Point Bugs ??

This is a common problem. As you already may have heard, computers have

trouble representing fractions. eg represent 1/3 as a binary floating point

number is never right on the money, even in base 10 it's

333333333333333333333 ad-infintum.

Not familiar with VB persay but in other languages, yes. I noticed all your

numbers you add are 4 decimal places. If you need 4 decimal accuracy, you

could just dim 'a' as an double integer and multiply everything you want to

add to 'a' by 10,000 (ten thousand). When done all the adding, take the

integer result, and divide it by 10,000 (a/10000). The answer will be an

integer devoid of any fractional amount. Your 'if a<>100 then' should pass.

This probably may or may not solve tour problem, but I thought I'd throw it

out at ya.

There are other ways to skin a cat. The problem is to find out why you skin

the cat in the first place ;-)

Quote:

> I have just encountered a problem with VB 4.0 16bit (Enterprise Edit)

when

> I am trying

> to sum a series of non-integers, the result is quit strange and I am

wonder

> if this is my

> fault or its the problem of VB4.0 ??

> Here is the codes :

> Dim a As Double

> a = 0#

> a = a + 62.3797

> a = a + 27.6776

> a = a + 4.2657

> a = a + 2.4969

> a = a + 1.8113

> a = a + 1.0856

> a = a + 0.2832

> If a <> 100 Then

> MsgBox format(a)+" not equal 100"

> End If

> The result should be 100.0 however, the program keeps going into the IF

> control, is it a bugs of VB4.0 ??

> Any comments are welcome, pls reply to my email address as well.

> --

> eRic

> http://www.asiaonline.net/users/~eeee