Hi all i am doing a program to round the text entered in a text box . Sample inputs
Entered value output value
100 100.00
50 50.00
Like this i would like to format my text box value on textBox1_Leave event
I tried this but didn’t work for me
private void textBox1_Leave(object sender, EventArgs e)
{
string str = string.Format(textBox1.Text, "##.00");
textBox1.Text = str;
}
Can any one help me
You’ll need to convert that string to an number, then call Format. Also, you were using format incorrectly. You’ll need to use a placeholder, like this
Naturally this will puke if you put in non-numeric input. To allow for this, you can do some basic validation