Solved

convert varchar into float in classic asp

Posted on 2011-03-21
10
2,916 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

760 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

21 Experts available now in Live!

Get 1:1 Help Now