Culture info usage while converting string to float type

8 Views Asked by At

I am trying to convert the input that I got from the user(string)to float and for float number format(15.6,4.5...)

string checkedNumber = txtResult.Text.Replace(',', '.'); number1 = Convert.ToSingle(checkedNumber); I already tried that but it didnt help So I updated now
string checkedNumber = txtResult.Text.Replace(',', '.'); number1 = Convert.ToSingle(checkedNumber, CultureInfo.InvariantCulture); to this and now its working but; My first question is if I am converting a type to float type shouldnt ToSingle() method be able to converting float type numbers(15.6) correctly.Example calculation when I dont use InvariantCulture: 5.4 + 1 = 55 And my second question is I couldnt really understand the functioning of Invariant Culture?And last one is how could I fix this problem if I didnt use InvariantCulture. Thank you in advance for your answers.

0

There are 0 best solutions below