Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want to insert float value into database table.
eg:
i have int a=2,int b=3
float c=(a/b)*100;
i want to insert value "c" into database table.(with 2 decimal places eg:83.22)
what query should i write.to store "c" value i have percentage with float datatype in my table.
Posted

first of all you need to change your code to get correct value with decimal places, for example
C#
float c =((float)a/b)*100;

otherwise you will get zero as result.
then read SQL Server Data Type Mappings[^] find the maping data type for the .net data type
 
Share this answer
 
Comments
batman56 28-Feb-15 11:25am    
thank you.
Sergey Alexandrovich Kryukov 28-Feb-15 12:57pm    
5ed.
—SA
The show of percentage sign is only for the UI presentation, there is no need to store it to database. In your case, set the date type of the database table column to decimal[^] with the appropriate precision and scale. Use Insert Into[^] to insert the value into the table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900