Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void TextBox_TextChanged(object sender, EventArgs e)
    {
    string value = TextBox.Text.Replace(",", "");
    long ul;
    if (long.TryParse(value, out ul))
    {
        TextBox.TextChanged -= TextBoxTextChanged;
        TextBox.Text = string.Format("{0:#,#0}", ul);
        TextBox.SelectionStart = TextBox.Text.Length;
        TextBox.TextChanged += TextBoxTextChanged;
    }
}


I used above code for making Calculator. I want to get result by

pressing equal comma with decimal value. Normally I can type

1,234.1234 in the textBox but if I press 1,000.123 + 1,000.123

it does not give the result 2,000.246 - it gives result only

2000.246. I mean comma with decimal value not getting by

pressing equal.

Can anybody kindly please help me to solve this problem ?

What I have tried:

I used above code for making Calculator. I want to get result by

pressing equal comma with decimal value. Normally I can type

1,234.1234 in the textBox but if I press 1,000.123 + 1,000.123

it does not give the result 2,000.246 - it gives result only

2000.246. I mean comma with decimal value not getting by

pressing equal.

Can anybody kindly please help me to solve this problem ?
Posted
Updated 17-Jul-16 4:21am
v2
Comments
Kornfeld Eliyahu Peter 17-Jul-16 9:49am    
Where is your code for 'pressing equal'!
Changing the value of a text box from code does not fire change event!

1 solution

C#
string whatYouWant = number.ToString("#,##0");


C#
String.Format("{0:n}", 1234);

string.Format("{0:n0}", 9876); // no digits after the decimal point.


format your output value also.
 
Share this answer
 
Comments
Member 12639198 18-Jul-16 2:58am    
Sorry Sir, not getting required result.
nilesh sawardekar 18-Jul-16 3:23am    
what output your getting by this?
Member 12639198 18-Jul-16 10:17am    
If I press 1,000.123 + 1,000.123 it does not give the result 2,000.246 - it gives result only 2000.246 I mean comma with decimal value not getting by pressing equal.
nilesh sawardekar 19-Jul-16 1:27am    
1,000.123 + 1,000.123 = AnyFormatGivenInReply(2000.246)

A+B=AnyFormatGivenInReply(C)

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