c# - How to format a string to add commas in thousands place for a number

String format to add commas in thousands place for a number
add-commas-in-thousands-place-for-a-number.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.Text = "";
        string s = string.Format("{0:n0}",1234567890);
        Label1.Text += "number: 1234567890";
        Label1.Text += "<br />Thousands Separator: " + s;

        Label1.Text += "<br/><br />another solution";
        int number = 1234567890;
        string formatedstring = number.ToString("#,##0");
        Label1.Text += "<br />result: " + formatedstring;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>c# example - string format to add commas in thousands place for a number</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkBlue; font-style:italic;">
            c# example - add commas in thousands place
            <br /> for a number using String.Format()
        </h2>
        <hr width="550" align="left" color="LightBlue" />  

        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Size="X-Large"
            >
        </asp:Label>
        <br /><br />
        <asp:Button 
            ID="Button1" 
            runat="server" 
            Text="add commas in thousands place for a number" 
            OnClick="Button1_Click"
            Height="40"
            Font-Bold="true"
            />
    </div>
    </form>
</body>
</html>
More c# examples