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

Last Reply 7 months ago By pandeyism

Posted 7 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();
    }        

 

<h5>
<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" />
</h5>

 

<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>
</asp:DropDownList>
</p>

 

Posted 7 months ago

Hey micah,

Please refer below sample.

HTML

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

Namespaces

C#

using System.Globalization;

VB.Net

Imports System.Globalization

Code

C#

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;
}

VB.Net

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

Namespaces

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