how to compare float value with a zero

# Thread: how to compare float value with a zero

1. Senior Member
Join Date
Dec 1969
Posts
236

## how to compare float value with a zero

I have <BR>tax = 0.097 //rsInvoice("tax") value<BR><BR>Now I need to compare and see if this is greater than zero or not.<BR><BR>If tax &#062; 0 then <BR>step1 <BR>else<BR>step 2 <BR>end if <BR><BR>***gives me error type mismatch<BR><BR>If i do <BR><BR>If CStr(tax) &#062; "0" then <BR>p_tax = FormatCurrency((somevalue * tax),2)<BR>else<BR>step 2 <BR>end if <BR><BR>****the if comparision works but I get type mismatch in the calculation step.<BR><BR>I would appreciate if anyone can show me how to od that!!<BR><BR>Thanks<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Where is ...

...the tax value coming from???<BR><BR>If you did<BR> tax = Request("tax")<BR>then it will *ALWAYS* be a string.<BR><BR>If you did<BR> tax = rsInvoice("tax")<BR>and the data type in the DB is DECIMAL or NUMBER, then it will be a type that VBScript can&#039;t do arithmetic (including comparisons) with.<BR><BR>However...<BR><BR>In both cases, the solution is easy:<BR> tax = CDBL( tax )<BR><BR>CDBL is a VBS function, but it actually calls outside of VBS to a very very smart function (if you care, it&#039;s the COM function VariantChangeTypeEx) that *can* convert most anything to most anything. And CDBL ask for the string or decimal value to be converted to a real number (a DOUBLE type) that VBS *can* work with.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
236

## RE: Where is ...

Tax value is coming from the table (db)<BR>thank you very much I will try !

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•