Problem comparing double values
- From: Chris Eden <ec2208@xxxxxxxxxxx>
- Date: Tue, 05 Jul 2005 04:43:10 -0700
Hello all, I have a strange problem that I would appreciate any help
with. I have an application that involves a comparison of two numbers,
one of which is made up of the sum of the values in an array. The code
is as follows:
Private Sub CompareNumbers()
Dim intIndex As Integer
Dim arNumbers(5) As Double
Dim dblTotal As Double
Dim dblComparison As Double
arNumbers(0) = 16843.2
arNumbers(1) = 40348.41
arNumbers(2) = 371910.18
arNumbers(3) = 148183.27
arNumbers(4) = 29183.96
arNumbers(5) = 143530.98
For intIndex = 0 To 5
dblTotal = dblTotal + arNumbers(intIndex)
Next
dblComparison = 750000
If dblComparison = dblTotal Then
MsgBox "Array Total:" & Chr$(9) & dblTotal & vbCr & "Comparison:" &
Chr$(9) & dblComparison & vbCr & "Numbers match"
Else
MsgBox "Array Total:" & Chr$(9) & dblTotal & vbCr & "Comparison:" &
Chr$(9) & dblComparison & vbCr & "No match"
End If
End Sub
Notice the oddity? The numbers are apparently identical and yet
according to the code, they do not match. What is even more bizzare is
that if I reduce the total of the numbers in the array to 597000, made
up of the following:
'' arNumbers(0) = 57843.2
'' arNumbers(1) = 44348.41
'' arNumbers(2) = 371910.18
'' arNumbers(3) = 50183.27
'' arNumbers(4) = 29183.96
'' arNumbers(5) = 43530.98
the comparison suceeded.
I don't think I have ever come up against anything so strange or so
frustrating; if anyone can shed any light on this it would be greatly
appreciated.
Thanks in advance
Chris
*** Sent via Developersdex http://www.developersdex.com ***
.
- Follow-Ups:
- Re: Problem comparing double values
- From: Chris Eden
- Re: Problem comparing double values
- From: Rick Rothstein
- Re: Problem comparing double values
- From: Al Reid
- Re: Problem comparing double values
- From: Tony Proctor
- Re: Problem comparing double values
- Prev by Date: Re: Programatically design a form
- Next by Date: Re: Default Property in VB6 Class
- Previous by thread: Accessing Outlook Address Book through Javascript or vbscript
- Next by thread: Re: Problem comparing double values
- Index(es):
Relevant Pages
|