0

I have a problem with texbox i want transform the content of textbox to float. I have this code:

 textBoxX.Text = String.Format("{0:N2}", decimal.Parse(textBoxX.Text));
                    textBoxY.Text = String.Format("{0:N2}", decimal.Parse(textBoxY.Text));
                    textBoxZ.Text = String.Format("{0:N2}", decimal.Parse(textBoxZ.Text));
                    var X = float.Parse(textBoxX.Text);
                    var Y = float.Parse(textBoxY.Text);
                    var Z = float.Parse(textBoxZ.Text); Function(X,Y,Z); 

If I put "3.5" in TextBoxX, var X gives me X= 35.0 but if I put "3,5" X give me 3.50. how can I fix this problem, I want that point and comma to transform into 3.50

Sami Ullah
  • 121
  • 6
Neimex23
  • 1
  • 1
  • It's a comma, not a colon, and that's not going to happen automatically, so you need to do it manually. Every culture is going to interpret a dot in one way and a comma in the other way. If you want to interpret both the same way then you can't rely on culture-based conversions. You need to manually do your own conversion. – user18387401 Aug 14 '22 at 06:13
  • you can first replace "," to "." and then use invariant culture parsing by "float.Parse(text, CultureInfo.InvariantCulture);" – Sami Ullah Aug 14 '22 at 07:06

0 Answers0