vbscript mathematical expression not working

二次信任 提交于 2019-12-12 05:27:47

问题


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


回答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().



来源:https://stackoverflow.com/questions/13569944/vbscript-mathematical-expression-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!