13,201,452 members (70,213 online)
Rate this:
See more:
hello friend .....

i have textbox in which i enter like 50 or 60 and i want to show result like 50.00 as i leave textbox ....can any buddy help me what i have to do...

Lakhan
Posted 27-Dec-11 4:05am

Rate this:

## Solution 1

`string  valueString = string.Format("{0:#.00}", value);`
Espen Harlinn 30-Dec-11 9:28am

5'ed!
Rate this:

## Solution 2

Espen Harlinn 30-Dec-11 9:28am

5'ed!
Rate this:

## Solution 3

Hello,
If you enter into textbox a number that belongs to the set of real numbers,
you should know that the value of the text box is still
simple text or string.Entered number as a string shuld be transfered to real number.
So you first need to know whether the user entered number.
For this I usually use TryParse method, afther that if user have
entered the number you should round it if it have more than
two decimal places Math.Round(Number,2),
and the last is to show it in the text box
as a plain text or a string in following format "60" -> "60.00",
by using Number.ToString("### ##0.00") witch transfers real number to simple string with shown string format and round it to two decimals:

```
string Text = " ";
double Number = 0;
bool IsReal = false;

Text = textBox1.Text;
IsReal = double.TryParse(Text,out Number);
if (IsReal)
{
Number = Math.Round(Number,2);
textBox1.Text = Number.ToString("### ##0.00");
}
else
{
MessageBox.Show("You did not entered the number !");
}```

Using string format "### ##0.00" inside the Number.ToString(),
you get rounded number to two decimal places so you usually do not need to use
Math.Round(Number,2), and the thousands are separated by space :

2.30
123.56
1 236.30
100 001.65
etc.

Try reading help instructions for string formatting inside your's programming language.There is a lot more to learn.

Bevare the code submited with this solution only works for double type of variables...

All the best,
Perić Željko
v5
Espen Harlinn 30-Dec-11 9:29am

Nice effort, my 5
Rate this:

## Solution 4

```private void textBox1_Leave(object sender, EventArgs e)
{
string str = String.Format("{0:F2}", Double.Parse(textBox1.Text));
textBox1.Text = str;
}```
LAKHANP22 28-Dec-11 0:33am

THANKS DORABABU743........
Dorababu743 28-Dec-11 2:56am

Mark as an answer if you get solved...
Espen Harlinn 30-Dec-11 9:30am

Fair enough - 5'ed!
Rate this:

## Solution 5

Write Code at Leave event of text box.

TextBox.Text = (Math.Round(Convert.ToDecimal(TextBox.Text),2)).ToString();
Espen Harlinn 30-Dec-11 9:30am

Fair enough - 5'ed!

Top Experts
Last 24hrsThis month
 OriginalGriff 300 Richard MacCutchan 125 Dave Kreskowiak 80 GKP1992 75 Karthik Bangalore 70
 OriginalGriff 8,060 ppolymorphe 2,014 Karthik Bangalore 1,724 CPallini 1,208 Jochen Arndt 1,075

Web02 | 2.8.171020.1 | Last Updated 28 Dec 2011