Bug in Int() and Numbers 
Author Message
 Bug in Int() and Numbers

Hi,

In VB6 with Windows 98 (all SPs), I found these bugs (3 years ago) to alert
people here:

1.  Dim q As Double, r As Double
q = 8.155
q = q * 1000
r = Int(q)

The result is r=8154.  MS told me that the Int() has some problem.

2. Dim s As Single

s=8.1
s=s+0.01

The result is r=8.110001.  The Single should be accurate to about 7 digits.
MS give me a lenghty explanation such as it is their way to implement
IEEE754 standard.  I told them it does not happen in MS Access.  Finally
they told me I should use Double.

Please let me know if you have some comments

Steve Ma



Sat, 25 Sep 2004 00:13:52 GMT  
 Bug in Int() and Numbers

<cut>

Quote:
> 1.  Dim q As Double, r As Double
<cut>
> The result is r=8154.  MS told me that the Int() has some problem.
<cut>
> I told them it does not happen in MS
> Access.  Finally they told me I should use Double.

> Please let me know if you have some comments

Access and VB are just rounding a bit differently.  Floating point values
are always prone to this kind of error.  You'd probably do better using
Currency or Decimal instead of either Single or Double if you need a
specific number of digits accurately.  Either that or do your own rounding.


Sat, 25 Sep 2004 01:20:21 GMT  
 Bug in Int() and Numbers
Use cint() or clng() rather than Int().


Quote:


> <cut>
> > 1.  Dim q As Double, r As Double
> <cut>
> > The result is r=8154.  MS told me that the Int() has some problem.
> <cut>
> > I told them it does not happen in MS
> > Access.  Finally they told me I should use Double.

> > Please let me know if you have some comments

> Access and VB are just rounding a bit differently.  Floating point values
> are always prone to this kind of error.  You'd probably do better using
> Currency or Decimal instead of either Single or Double if you need a
> specific number of digits accurately.  Either that or do your own
rounding.



Sat, 25 Sep 2004 06:15:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ???Bug in Int()-function of ACC95 and ACC97 ???

2. Bug when ising INT function

3. TERRIBLE BUG IN INT FUNCION???????????????????

4. BUG: VB4(16 bit) - Int and Fix functions don't work correctly

5. BUG?? Weird Int rounding

6. Q: INT - LONG NUMBER - ARRAY

7. Converting BitArray to Int and Int to BitArray

8. How to display int, short int range values

9. Int to Str or Str to Int ??

10. Converting ULONG (4 byte binary) int VB Long / SQL INT for DTS Import

11. Convert Int to Str & Str to Int

12. int main( int argc, char *argv[]) in VB??

 

 
Powered by phpBB® Forum Software