C# Format Integer (Commas)

Posted on 2007-10-09
Last Modified: 2012-05-05
Visual Studio 2005 C#.Net 2.0

We have an application that computes an integer values, and then displays the value in a TextBox; very simple.
We would like to format the Integer value to include commas example:

54345         should be 54,345
123456789 should be 123,456,789

And we don't know how.
Thank you in advance.//
Question by:bmiller250
    LVL 23

    Expert Comment

    by:Ashish Patel

    Author Comment

    Like thiss:

    txtTotal.Text = String.Format({0:n}, "123465");
    LVL 23

    Expert Comment

    by:Ashish Patel
    Try this
    txtTotal.Text = "123465".Format({0:n});
    LVL 96

    Accepted Solution

    1) You can't format string text as numeric

    2) You would need a numeric type to perform that function

    3) double n = 123456;
         this.txtTotal.Text = n.ToString("N0");


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now