I have given a default value “2.5” for a textbox called “diff_Box” and then in order to check something in another purpose, I took this value and paste it into another textbox called “textbox5”. But in textbox5 it is displayed as 25. I know it is a very common issue but I can not solve it somehow. I have tried sofar;
double diff;
diff = Double.parse(diff_Box.Text);
diff = Convert.ToDouble(diff_Box.Text);
textBox5.Text = Convert.ToString(diff);
textBox5.Text = diff.ToString("F2");
textBox5.Text = ToString.parse(diff);
but I am encountering all the time the same problem
thanks in advance


The problem is that you are not using the format used by your system UI culture. You actually are using the
InvariantCultureon your GUI.You use a
.in the textbox. I assume your current UI culture uses,. Therefore it sees no digits after the.and results in25.0instead of2.5.This line will convert back using the InvariantCulture instead of the system UI culture:
The better approach however is to use a private
Double _diffand just convert it to the required culture for display on the form. Second, you should expect the users to use the UI culture for data-entry.