2 Double numbers, same value not equal in LotusScript?

HiIn LotusScript

I have totalDR=3000.28 (Double)

totalCR=3000.28 (Double)

The numbers are totally equal

Why does this if statement go to the else condition?

If totalDR = totalCR Then

	isTotalDRCROkay = True

Else

	isTotalDRCROkay = False

End If

Thanks to all who posted replies - very informative.

Jeff

Subject: 2 Double numbers, same value not equal in LotusScript?

Because you’re using the wrong operator… = is different than ==…

When comparing 2 values for equality, you must use the equality operator “==”.

When you want to set a variable to a value, you use the = operator.

The correct code should be:

If totalDR == totalCR Then

	isTotalDRCROkay = True

Else

	isTotalDRCROkay = False

End If

EDIT: Sorry, my mistake… == is the same as = in LotusScript language… Add some debug prompts to your script to confirm the content of each variable… I can’t see why it wouldn’t work from that code…

Subject: That is not true

It is true in C, but not in LotusScript. In LotusScript, a single = is used for both purposes.

Subject: Woops

You’re right I didn’t know that… old habbits die hard hehe.

Well, can you see whhy his script would return false then?

Subject: *Rounding error. Just because it looks like a two digit precision doesn’t mean it is internally

Subject: RE: *Rounding error. Just because it looks like a two digit precision doesn’t mean it is internally

Thanks, saw your response after I posted this… you’re too quick :slight_smile:

Subject: 2 Double numbers, same value not equal in LotusScript?

It is almost certainly that they are not really equal, but just equal enough to the level of precision you are showing. For example 3000.279999999998 and 3000.28000000000001 may both show up as 3000.28 depending on the level of precision you are showing, but that doesn’t make them equal. I think there is an @function in 6.5.1 that checks to within a level of precision, but I don’t recall what it is.

Subject: @FloatEq (was: 2 Double numbers, same value not equal in LotusScript?)

Subject: 2 Double numbers, same value not equal in LotusScript?

People already answered the “why” part in this thread. If you are asking for a solution, try this:

If Abs(totalDR - totalCR) < 0.00001 Then

…

Else

…

End If

You can further reduce the 0.00001 part if you need more precision.