Comparing Doubles

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top