Convert Number to string with Thousand Separator in C# and VB.Net

Last Reply 3 months ago By pandeyism

Posted 3 months ago

how can i format figures like 1200000 to something like money figures with comers like 1,200,000

    protected void ddlcuomerphone_SelectedIndexChanged(object sender, EventArgs e)
        DataTable dt = GetDataTable("SELECT SUM (Debt) Debt FROM CustomerDetail WHERE CustomerPhone = '" + ddlcuomerphone.SelectedItem.Text.Trim() + "'");
        lbldebt.Text = dt.Rows[0]["Debt"].ToString();


<asp:Label ID="Label2" runat="server" Text=" Total Debt /" Font-Size="Large" ForeColor="#CC3300"></asp:Label>
<asp:Label ID="lbldebt" runat="server" Font-Size="Large" ForeColor="#006600" />


<p class="">
<asp:DropDownList ID="ddlcuomerphone" runat="server" OnSelectedIndexChanged="ddlcuomerphone_SelectedIndexChanged"
    AutoPostBack="True" AppendDataBoundItems="true" CssClass="btn btn-default dropdown-toggle">
    <asp:ListItem Text="Select Customer Unique Phone Number" Value=""></asp:ListItem>


You are viewing reply posted by: pandeyism 3 months ago.
Posted 3 months ago

Hey micah,

Please refer below sample.


    Inetger Amount:
    <asp:Label ID="lblAmountInteger" runat="server" /><br />
    Decimal Amount:
    <asp:Label ID="lblAmountDecimal" runat="server" />



using System.Globalization;


Imports System.Globalization



protected void Page_Load(object sender, EventArgs e)
    int amountInInteger = 1200000;
    double amountIndecmal = 1200000.00;
    string amountInInetgerFormat = amountInInteger.ToString("#,##0");// for integer value
    string amountInDecimalFormat = amountIndecmal.ToString("N", new CultureInfo("en-US"));// for decimal value
    lblAmountInteger.Text = amountInInetgerFormat;
    lblAmountDecimal.Text = amountInDecimalFormat;


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim amountInInteger As Integer = 1200000
    Dim amountIndecmal As Double = 1200000.0
    Dim amountInInetgerFormat As String = amountInInteger.ToString("#,##0")
    Dim amountInDecimalFormat As String = amountIndecmal.ToString("N", New CultureInfo("en-US"))
    lblAmountInteger.Text = amountInInetgerFormat
    lblAmountDecimal.Text = amountInDecimalFormat
End Sub


Inetger Amount: 1,200,000
Decimal Amount: 1,200,000.00