Convert number in textbox to float C#

Josef picture Josef · Apr 4, 2013 · Viewed 35.6k times · Source

I have textbox that accept numbers. Those numbers will be saved in database. When I enter number like 2,35 and convert to float and send to database I get error because database accept only number with dot, e.g. 2.35

float num = float.Parse(textBox1.Text);

num is still 2,25

How to manage that? I've tried with CultureInfo.InvariantCulture but I never get what I want

Answer

ShaileshDev picture ShaileshDev · Jun 30, 2015

You can try the following:

float.Parse(textBox1.Text.Trim(), CultureInfo.InvariantCulture.NumberFormat);

I hope this would've solved the issue.