Thread: compare values
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Steve Steve is offline
external usenet poster
 
Posts: 1,814
Default compare values

I increased to 123 decimal places and there are no differences.

"Pete_UK" wrote:

Increase the number of decimal places shown for cells E1 and E2 and
you will see that they are not exactly equal. This is a common problem
with computers which use binary numbers to represent decimals - some
decimal fractions cannot be represented exactly with binary fractions,
and so rounding errors occur.

I'm sure that JoeU will give a more detailed explanation.

Hope this helps.

Pete

On Sep 21, 4:23 pm, Steve wrote:
I have a problem in a macro where I'm comparing two values. They appear to
be the same but when tested in the code, are different. I recreated the
problem using this scenario:

A1-D1 = .2003, .0542, .0257 and 0, respectively.
A2-D2 have the same values.

E1 = .2802
E2 = the formula sum(A2:D2)

When I run the following code I get the message box values ".2802", ".2802"
and "False". The funny thing is...if I type a formula in the worksheet
=E1=E2 I get "True":

Sub testit()
frst = Range("E1").Value
Scnd = Range("E2").Value
MsgBox frst
MsgBox Scnd
MsgBox (frst = Scnd)
End Sub