Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, can someone help me with textbox? i got textbox1 and i only input numbers, i wanted to format it to numbers after Text_Leave Event:

For Example :
I input 122333

Output must be:
122,333.00


here's my code in text_leave
string a;
           double bb = double.Parse(textBox1.Text);

  a = Double.ToString("#,0.##");


The output in textbox.Text became #,0.##

Please help Thanks!
Posted

Try:
C#
string a;
double bb;
if (!double.TryParse(textBox1.Text, out bb))
   {
   // Report a problem to the user.
   ...
   }
else
   {
   a = bb.ToString("#,000.00");
   ...
 
Share this answer
 
Try string.Format("{0:n0}", bb);.
 
Share this answer
 
I think you will find the help you need reading the info on MSDN: Custom Numeric Format Strings[^]

It also depends on the localization setting you have on your computer.
 
Share this answer
 
Comments
Rencyrence 11-Nov-15 20:00pm    
It helps a lot, thanks :)
George Jonsson 11-Nov-15 20:25pm    
You are welcome

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