String format, thousand separator and decimals

Discussion in 'ASP .Net' started by hansiman, Oct 8, 2004.

  1. hansiman

    hansiman Guest

    In a datagrid I want to format a sql db bigint field with zero
    decimals as 1.000.000 where full stop (.) separates thousands.

    I use:
    <%# DataBinder.Eval( Container, "DataItem.Amount", "{0:0,0}") %>

    ....and get 1,000,000 (where there is a value and 00 (double zero)
    where there is none.

    The comma I know is thousand separator, however, I don't know how to
    change it to a full stop (.).

    That I get 00 (double zero) I don't understand...

    Please give me a hint.

    hansiman, Oct 8, 2004
    1. Advertisements

  2. hansiman

    Guest Guest


    You need to change the NumberGroupSeparator so it doesn't use "," but uses
    ".". That's in the System.Globalization namespace. You'll probably need a
    helper function to do the work. See the example code below.

    I've used a Long in the sample because it seems to be the same as a SQL

    Let us know if this helps?

    Microsoft MVP [ASP.NET]

    <%@ Page Language="VB" %>
    <script runat="server">

    sub Page_Load
    if not ispostback then
    end if

    end sub
    Function Fixbigint(lng as long) as string
    Dim nfi As System.Globalization.NumberFormatInfo = _
    New System.Globalization.CultureInfo _
    ("en-US", False).NumberFormat
    ' lng=9223372036854775807
    nfi.NumberGroupSeparator ="."
    return lng.ToString("N", nfi)
    end function

    Function CreateDataSource() As
    Dim dt As New
    Dim dr As
    dt.Columns.Add(New _
    ("id", GetType(Int32)))
    dt.Columns.Add(New _
    ("itemdesc", GetType(String)))
    dt.Columns.Add(New _
    ("along", GetType(Long)))
    dt.Columns.Add(New _
    ("Boolean", GetType(Boolean)))
    Dim i As Integer
    For i = 0 To 8
    dr = dt.NewRow()
    dr(0) = i
    dr(1) = "Item " + i.ToString()
    dr(2) = 92233720368547758 + i
    dr(3) = (i = 4)
    Next i
    Return dt
    End Function 'CreateDataSource

    <form runat="server">
    <asp:Label id="Label1" runat="server"></asp:Label>
    <asp:DataGrid id="DataGrid1" runat="server"
    <asp:TemplateColumn HeaderText="along">
    <asp:Label runat="server" text='<%#
    Fixbigint(DataBinder.Eval(Container, "DataItem.along")) %>'></asp:Label>
    Guest, Oct 8, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.