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
That’s because the
Doubleyou’re converting to is a floating point.Why convert to
Doublewhen you are dealing with currencies? UseCCur()instead ofCDbl().