format for decimal values

Discussion in 'ASP .Net' started by Nariban Barkan, Jun 9, 2008.

  1. Hi All,

    I have a decimal value on the GridView BoundField which comes from sql
    server and it seems on gridview like that;
    2096.62
    14899.01

    I want to display that values like
    2.096,62
    14.899,01

    Thanks for any help
    Nariban Barkan, Jun 9, 2008
    #1
    1. Advertising

  2. Nariban Barkan

    Pavel Minaev Guest

    On Jun 9, 11:50 am, "Nariban Barkan" <> wrote:
    > Hi All,
    >
    > I have a decimal value on the GridView BoundField which comes from sql
    > server and it seems on gridview like that;
    > 2096.62
    > 14899.01
    >
    > I want to display that values like
    > 2.096,62
    > 14.899,01
    >
    > Thanks for any help


    If you want to use locale-dependent group separator and decimal point,
    then you need the "N" format specifier.
    Pavel Minaev, Jun 9, 2008
    #2
    1. Advertising

  3. Nariban Barkan

    Mihai N. Guest

    > I have a decimal value on the GridView BoundField which comes from sql
    > server and it seems on gridview like that;
    > 2096.62
    > 14899.01
    >
    > I want to display that values like
    > 2.096,62
    > 14.899,01



    Convert to a double with Parse (or TryParse), then use ToString("N")
    (or ToString("N",culture) if you want a culture other than the current one)



    --
    Mihai Nita [Microsoft MVP, Visual C++]
    http://www.mihai-nita.net
    ------------------------------------------
    Replace _year_ with _ to get the real email
    Mihai N., Jun 9, 2008
    #3
  4. Thanks all..

    and can i add a special tag or a custom currency mark after or before the
    value on the BoundField column ?
    Nariban Barkan, Jun 9, 2008
    #4
  5. Nariban Barkan

    siccolo Guest

    siccolo, Jun 9, 2008
    #5
  6. Nariban Barkan

    Pavel Minaev Guest

    On Jun 9, 12:50 pm, "Nariban Barkan" <> wrote:
    > Thanks all..
    >
    > and can i add a special tag or a custom currency mark after or before the
    > value on the BoundField column ?


    Then you need custom number format such as "#,##0.00'tag'" (note the
    single quotes around 'tag' - they will ensure it is treated as a
    literal string).
    That's for CellFormatting event, though. For CellParsing, which you'll
    also need for full two-way data binding, you'll probably want to trim
    the tag/mark with String.Substring first, and then run it through
    Decimal.Parse.

    In general, I'd recommend searching MSDN for "Custom Numeric Format
    Strings". It has more detailed explanations of what you can do with
    this, and how.
    Pavel Minaev, Jun 10, 2008
    #6
  7. Nariban Barkan

    Mihai N. Guest

    > Then you need custom number format such as "#,##0.00'tag'" (note the
    > single quotes around 'tag' - they will ensure it is treated as a
    > literal string).


    Proper locale-aware formatting is done by setting
    NumberFormatInfo.CurrencySymbol and using ToString("C", ...)
    A currency format is not just a number format with currency attached to it
    (even in US -123 migh be represented as (123) when it's about financial
    stuff)



    --
    Mihai Nita [Microsoft MVP, Visual C++]
    http://www.mihai-nita.net
    ------------------------------------------
    Replace _year_ with _ to get the real email
    Mihai N., Jun 11, 2008
    #7
  8. Nariban Barkan

    Pavel Minaev Guest

    On Jun 11, 10:18 am, "Mihai N." <> wrote:
    > > Then you need custom number format such as "#,##0.00'tag'" (note the
    > > single quotes around 'tag' - they will ensure it is treated as a
    > > literal string).

    >
    > Proper locale-aware formatting is done by setting
    > NumberFormatInfo.CurrencySymbol and using ToString("C", ...)
    > A currency format is not just a number format with currency attached to it
    > (even in US -123 migh be represented as (123) when it's about financial
    > stuff)
    >
    > --
    > Mihai Nita [Microsoft MVP, Visual C++]http://www.mihai-nita.net
    > ------------------------------------------
    > Replace _year_ with _ to get the real email


    That's assuming the original question was about locale-specific
    currency formatting. However, the request was about "special tag or a
    custom currency mark" - which, as I understand it, assumes that it is
    not locale-dependent (and, indeed, may not be a currency sign at all,
    merely something similar).
    Pavel Minaev, Jun 11, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shannon
    Replies:
    1
    Views:
    8,591
  2. shannon
    Replies:
    0
    Views:
    567
    shannon
    Feb 1, 2006
  3. Ven
    Replies:
    3
    Views:
    1,316
  4. Gilbert Fine
    Replies:
    8
    Views:
    894
    Zentrader
    Aug 1, 2007
  5. Fei Liu
    Replies:
    21
    Views:
    2,346
    John Bokma
    Dec 16, 2006
Loading...

Share This Page