View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Comparing Doubles

big t,
Depending on the nature of the comparison, something like:

If Abs(UserCompSum-TestValue)<Threshold Then
You would have to decide on the Threshold value that you can tolerate.

NickHK

"big t" wrote in message
...
Hi everyone,

I have a section of code where I'm trying to see if a variable
(UserCompSum), declared as a double, is equal to 100, like this:

Dim UserCompSum As Double

If UserCompSum = 100 Then
bUserCompSum = True
End If

but even when UserCompSum is equal to 100 the code doesn't seem to think

so
and I get stuck with bUserCompSum = False.

I have a workaround by doing this:

If CInt(UserCompSum) = 100 Then
bUserCompSum = True
End If

but this seem a little inelegant to me.

Does anyone know how to compare Double values?

TIA
big t