khurram
khurram

Reputation: 1070

vbscript mathematical expression not working

In my asp code, I have 4 variables with different values.

chAmount = 19.99
totalRefundAmount =0
voidQueueRefundAmount =15.99
amount=4

when I execute following statement

if (CDbl(chAmount) + CDbl(totalRefundAmount) - CDbl(voidQueueRefundAmount) - CDbl(amount) < 0.00) then
end if

The if condition is true while it should not be because the answer of above expression should be 0 and it should not go in the if loop but it is going inside the loop .

I am getting -1.77635683940025E-15 in the visual studio debugger for the expression CDbl(chAmount) + CDbl(totalRefundAmount) - CDbl(voidQueueRefundAmount) - CDbl(amount)

see this following screenshot of visual studio debugger. http://screencast.com/t/73PyutXB07R1

Upvotes: 0

Views: 785

Answers (1)

That's because the Double you're converting to is a floating point.

Why convert to Double when you are dealing with currencies? Use CCur() instead of CDbl().

Upvotes: 1

Related Questions