Professional Web Applications Themes

add a comma - ASP.NET General

how do I format a databound field in a datagrid to place a comma for a currency (eg 126,000) I'm currently using: DataBinder.Eval(Container.DataItem, "price", "{0:c}" thanx...

  1. #1

    Default add a comma

    how do I format a databound field in a datagrid to place a comma for a
    currency (eg 126,000)

    I'm currently using:

    DataBinder.Eval(Container.DataItem, "price", "{0:c}"

    thanx


    Ryan Guest

  2. #2

    Default Re: add a comma

    You can use the ToString() method, and pass the string "N" to it, as in:

    decimal d = 100000.25
    string s = d.ToString("N"); // returns "100,000.25"

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    http://www.takempis.com
    The more I learn, the less I know.

    "Ryan Moore" <com> wrote in message
    news:phx.gbl... 


    Kevin Guest

  3. #3

    Default Re: add a comma

    Try using the DataFormatString Property of your boundcolumn:
    <asp:BoundColumn DataField="Price" DataFormatString="{0:c}" ... />

    David Wier
    http://aspnet101.com
    http://aspexpress.com


    "Ryan Moore" <com> wrote in message
    news:phx.gbl... 


    David Guest

  4. #4

    Default Re: add a comma

    "Ryan Moore" <com> wrote 

    Ryan,
    Try setting the CurrentCulture and CurrentUICulture for the current thread
    in the Application_BeginRequest event handler.

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    ' Initialize the CurrentCulture and CurrentUICulture with the
    ' Browser's user language setting.
    Try
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLang uages(0))
    Catch
    ' Culture not supported. Use US English.
    Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
    End Try
    ' Set the CurrentUICulture to be the same as CurrentCulture
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
    End Sub

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP
    http://www.able-consulting.com



    Carl Guest

  5. #5

    Default Re: add a comma

    This one has always been my favorite for currency in a datagrid.

    DataReader.GetSqlMoney(2).ToDouble().ToString(
    "$#,,##0.00;($#,##0.00);$0.00" );

    has dollar signs, commas and does the () around negative values...

    bill


    DataReader.GetSqlMoney( 2 ).ToDouble().ToString(
    "$#,##0.00;($#,##0.00)" ) );

    "Ryan Moore" <com> wrote in message
    news:phx.gbl... 


    William Guest

Similar Threads

  1. Replacement dot with comma
    By ElLamok in forum Macromedia Flex General Discussion
    Replies: 4
    Last Post: April 11th, 04:24 PM
  2. Separate from Comma
    By emmim44 in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 30th, 01:22 PM
  3. 14 decimals after comma
    By Dave_Saunders@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 29
    Last Post: September 30th, 01:09 PM
  4. Comma in the DataGrid
    By kksm8319 in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: November 18th, 08:17 AM
  5. dot and comma are changed
    By DA in forum Windows Server
    Replies: 0
    Last Post: June 10th, 09:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139