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

i just want to ask how to convert a number inside a textbox to float.
I have a textbox [TextBox1] which contains a number "1.5".
I have to insert "1.5" to database as a float. how can i get the value as a float? any suggestions?
Posted
Comments
BulletVictim 16-Sep-13 4:47am    
Try
float.Parse(TextBox1.Text, CultureInfo.InvariantCulture.NumberFormat);
or try using Double if you can

Try:
C#
float f = 0.0F;
if (float.TryParse(TextBox1.Text, out f))
   {
   // It converted ok
   }
 
Share this answer
 
Comments
Maciej Los 16-Sep-13 6:41am    
+5
You may use Single.Parse[^] or the Single.TryParse[^] method if you really need a Single (a Double could be a better option).
 
Share this answer
 
Comments
Maciej Los 16-Sep-13 6:41am    
+5
[no name] 16-Sep-13 8:00am    
+5

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