Solved

convert varchar into float in classic asp

Posted on 2011-03-21
10
2,972 Views
Last Modified: 2012-08-13
Hi
I want to convert varchar variable into float..
Is it possible in classic asp.
If yes can you give some example for me..

When i am inserting multiple records at a time, it is accepting only varchar datatypes..when i declare it as float it is not inserting..
so i want to convert it from varchar to float to make caluculations..


Thanks
0
Comment
Question by:lucky20
  • 6
  • 4
10 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 35180395
you can try using the CDbl() function:

num = "123.456"
num = CDbl( num )
0
 
LVL 1

Author Comment

by:lucky20
ID: 35180409
is that in sql or asp?
0
 
LVL 1

Author Comment

by:lucky20
ID: 35180419
oh sorry.. i got it..
i will try this
thanks
0
 
LVL 1

Author Comment

by:lucky20
ID: 35189901
can u give the sample program..how u use it in real programming?

Thanks
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 35189981
maybe if you show the code you're trying to get working, I can take a look and see if I can help you directly with that
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:lucky20
ID: 35190398
To be honest, I don't know how to use this in my program..

for i=1 to 5 
                    Set sql=Server.CreateObject("ADODB.Command")  
                    sql.ActiveConnection=Conn 
                    getquantity = request.form("quantity_"& i)
                    getitemid = request.form("itemid_"& i)
                    getcase=request.form("case_"& i)
                    
                    if getitemid <> "" and getquantity <> ""and getcase <> "" then  
                    sql.commandtext="insert into items(itemid,quantity,case_i,inventory_taken)values(?,?,?,getdate())"
 sql.Parameters.Append sql.CreateParameter("@itemid", adInteger, adParamInput, , getitemid)
                    sql.Parameters.Append sql.CreateParameter("@quamntity", advarchar, adParamInput,15 , getquantity)
                    sql.Parameters.Append sql.CreateParameter("@case_i", adVarchar, adParamInput,13 , getcase) 
                    sql.Execute
                    
                    end if
Next

Open in new window

       
       
Here quantity is declared as varchar in database.
(If i declare it as float,this insert statement is not working..so declared it as varchar)
But i need quantity values to make caluculations..

Thanks
So I want to convert it to varchar to float values
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 35190524
ok I thought you wanted the ASP equivalent, but it looks like you want the sql server equivalent. have a look at http://www.w3schools.com/ado/met_comm_createparameter.asp for a list of constants you can use. you want to use adSingle or adDouble:

sql.Parameters.Append sql.CreateParameter("@quamntity", adSingle, adParamInput,15 , getquantity)

also, it looks like you may have a typo in the parameter name (@quaMntity)
0
 
LVL 1

Author Comment

by:lucky20
ID: 35191402
ad single only takes single integer(4),
or if i use ad doublemit also takes only two digit numeric value(87).
Is there anything will accept 23.94(like float values).
0
 
LVL 1

Author Comment

by:lucky20
ID: 35191416
AdDouble will accept float values..I got it..

Sorry it was my mistake. I read desription of tinyint..
Thanks for information..
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 35191832
glad I could help :)

don't forget to close the question out!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now