PDA

View Full Version : Convernt String to Numeric


Carl
01-08-2003, 12:47 AM
Hi guys, simple question that I can't seem to find in my vbscript refrence. How do I convert a string to a numeric variable.

The string happens to be a cookie.

whammy
01-08-2003, 01:52 AM
First of all you want to be sure it exists...


If Request.Cookies("Cookiename") <> "" Then
If IsNumeric(Request.Cookies("Cookiename")) Then
' Do whatever you want here
End If
End If


Since all variables in ASP are actually of the type "Variant", you shouldn't have to "convert" it to numeric before performing a mathematical operation on it if it is indeed numeric (and I presume you set the cookie!). What are you trying to do, and what kind of information does the cookie contain? :)

P.S.
CInt(variable) = integer
CDbl(variable) = Double

and there's plenty more datatypes, look on MSDN

Carl
01-08-2003, 01:59 AM
Thanks that code below works.