I want to implement thousand separator in Windows 10 calculator in textbox....

c00012 746 Reputation points
2021-08-04T11:18:28.66+00:00

Hello,

I want to implement thousand separators in Windows 10 calculator in Textbox:

120450-ezgifcom-gif-maker.gif

if someone gives me a good advice, I'd be very appreciated.

thanks,

c00012

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2021-08-05T02:33:35.407+00:00

    The following code could implement the thousands separator. Is it suitable for your situation?
    The code of xaml:

     <TextBox Name="textBox"  TextChanged="textBox_TextChanged"/>  
    

    The code of xaml.cs:

    private void textBox_TextChanged(object sender, EventArgs e)  
            {  
              if (!string.IsNullOrEmpty(textBox.Text))  
              {  
                System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");  
                var valueBefore = Int64.Parse(textBox.Text, System.Globalization.NumberStyles.AllowThousands);  
                textBox.Text = String.Format(culture, "{0:N0}", valueBefore);  
                textBox.Select(textBox.Text.Length, 0);  
              }  
            }  
    

    The result picture:

    120635-1.gif


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.