Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a text box in which enters hours like ex: 10.5 or 2.5 , so when the user enters just 10 or 2, then the text box should display ".0" as appended to 10 or 2.
and finally the textbox should contain a value as 10.0 or 2.0

how can i do this in C#?
Posted

On textbox leave event you can write the below code.

Example :

private void textBox1_Leave(object sender, EventArgs e)
{
textBox1.Text = Convert.ToDouble(textBox1.Text).ToString("0.0");
}
 
Share this answer
 
Comments
Member 10593922 18-Feb-14 0:49am    
thank u.. it was helpful. but i used LostKeyboardFocus in wpf
use
convert.ToDouble(txtbox) function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900