Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how to retrive float values from database into asp.net
Posted
Comments
AmitGajjar 21-Feb-12 4:46am    
if you have any problem in your code then post it here..

hai nabinaya,

you can simply write query "select value from table" and store the result in decimal value
 
Share this answer
 
Comments
nabinaya 21-Feb-12 4:56am    
Hi sir

Thanks for your reply..i tried that but i couldn't get.in my database the value is 2.5.but after convert that value it becomes 2.
how to slove this sir?
Hi, use below code to show the value

C#
decimal amt = (Convert.ToDecimal(dt.Rows[0]["Amount"].ToString())).ToString("0.00");


Don't forget to mark if it is your solution. :-)
 
Share this answer
 
v2
Comments
nabinaya 21-Feb-12 5:04am    
Hi sir,

thanks for your reply.
I gives an error as

"Cannot implicitly convert type 'string' to 'decimal'"
Aniket Yadav 21-Feb-12 5:07am    
Can you post your sample code of what have you done.

So that i can figure it out.

Also tell me the database field names and their datatypes.
Varun Sareen 21-Feb-12 5:30am    
sarvesh jee..you can't implicitly convert a string to decimal :)
Using the 2nd solution that will more than likely resolve your issue. I can't remember exactly but I'm not sure the ToString() method will work.

You need to provide some kind of formatting for the decimal value.

Instead of:
C#
.ToString("0.00");


Do this:
C#
.ToString("{0: 0.##}", 123.45);      // "123.45"
.ToString("{0: 0.##}", 123.4);       // "123.4"
.ToString("{0: 0.##}", 123.0);       // "123"
 
Share this answer
 
Try this:-

decimal amt=Math.Round(Convert.ToDecimal(dt.Rows[0]"Amount"].ToString()),2);


where Math.Round(decimalValue,numbers after decimal). Please refer the link:-

http://msdn.microsoft.com/en-us/library/75ks3aby.aspx[^]
 
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