{0:c} format in Gridview column to show $ regardless of browser country?

Discussion in 'ASP .Net' started by Mark B, Mar 30, 2009.

  1. Mark B

    Mark B Guest

    I want some numbers shown in a GridView column to show as e.g. $5,423.98
    even if the end user is in a foreign country which doesn't use dollars.

    What would I put in place of {0:c}?
    Mark B, Mar 30, 2009
    #1
    1. Advertising

  2. Mark B

    psycho Guest

    Re: {0:c} format in Gridview column to show $ regardless of browsercountry?

    On Mar 30, 11:47 am, "Mark B" <> wrote:
    > I want some numbers shown in a GridView column to show as e.g. $5,423.98
    > even if the end user is in a foreign country which doesn't use dollars.
    >
    > What would I put in place of {0:c}?


    I think that will make use of server's culture and not user browser's
    culture
    psycho, Mar 30, 2009
    #2
    1. Advertising

  3. Re: {0:c} format in Gridview column to show $ regardless of browsercountry?

    On Mar 30, 8:47 am, "Mark B" <> wrote:
    > I want some numbers shown in a GridView column to show as e.g. $5,423.98
    > even if the end user is in a foreign country which doesn't use dollars.
    >
    > What would I put in place of {0:c}?


    Hi Mark

    you would simply need to specify a value of culture attribute.

    Either use the web.config file to set it globally

    <globalization uiCulture="en" culture="en-GB" /> // e.g. to show £

    or set the Culture and UICulture attributes of the @ Page directive

    <%@ Page UICulture="en" Culture="es-GB" %>

    http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
    http://msdn2.microsoft.com/en-us/library/system.globalization.regioninfo.aspx

    Hope this helps
    Alexey Smirnov, Mar 30, 2009
    #3
  4. Mark B

    Mark B Guest

    Do you agree with:

    "I think that will make use of server's culture and not user browser's
    culture"?


    "Alexey Smirnov" <> wrote in message
    news:...
    On Mar 30, 8:47 am, "Mark B" <> wrote:
    > I want some numbers shown in a GridView column to show as e.g. $5,423.98
    > even if the end user is in a foreign country which doesn't use dollars.
    >
    > What would I put in place of {0:c}?


    Hi Mark

    you would simply need to specify a value of culture attribute.

    Either use the web.config file to set it globally

    <globalization uiCulture="en" culture="en-GB" /> // e.g. to show £

    or set the Culture and UICulture attributes of the @ Page directive

    <%@ Page UICulture="en" Culture="es-GB" %>

    http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
    http://msdn2.microsoft.com/en-us/library/system.globalization.regioninfo.aspx

    Hope this helps
    Mark B, Mar 30, 2009
    #4
  5. Re: {0:c} format in Gridview column to show $ regardless of browsercountry?

    On Mar 30, 12:41 pm, "Mark B" <> wrote:
    > Do you agree with:
    >
    > "I think that will make use of server's culture and not user browser's
    > culture"?
    >


    Mark, the GridView format is based on the current culture and to show
    it in USD to all users you have to set culture in "en-US". Currency
    format cannot be based just on the browser culture only, because it
    makes no sense as $5,423 not equals to £5,423, or 5,423 €. In this
    case you need to use an exchange rate to recalculate the value. If you
    need to have multiple currencies based on the browser settings check
    this tutorial at http://quickstarts.asp.net/quickstartv20/aspnet/doc/localization/culture.aspx.
    Hope this helps
    Alexey Smirnov, Mar 30, 2009
    #5
  6. Mark B

    Mark B Guest

    Yes but we'll need other parts in the GridView, e.g. DateTime values to be
    in the correct format for the end user (e.g. French, Chinese, Arabic). The
    only thing we want to override is the Amount column which is in USD.


    "Alexey Smirnov" <> wrote in message
    news:...
    On Mar 30, 12:41 pm, "Mark B" <> wrote:
    > Do you agree with:
    >
    > "I think that will make use of server's culture and not user browser's
    > culture"?
    >


    Mark, the GridView format is based on the current culture and to show
    it in USD to all users you have to set culture in "en-US". Currency
    format cannot be based just on the browser culture only, because it
    makes no sense as $5,423 not equals to £5,423, or 5,423 €. In this
    case you need to use an exchange rate to recalculate the value. If you
    need to have multiple currencies based on the browser settings check
    this tutorial at
    http://quickstarts.asp.net/quickstartv20/aspnet/doc/localization/culture.aspx.
    Hope this helps
    Mark B, Mar 30, 2009
    #6
  7. Re: {0:c} format in Gridview column to show $ regardless of browsercountry?

    On Mar 30, 9:46 pm, "Mark B" <> wrote:
    > Yes but we'll need other parts in the GridView, e.g. DateTime values to be
    > in the correct format for the end user (e.g. French, Chinese, Arabic). The
    > only thing we want to override is the Amount column which is in USD.


    Ah, but this is very simple. You don't need to use the formatting by
    culture in this case and instead of "{0:c}" - which is currency
    format, use "${0:n}" where $ - is your preferred currency symbol and n
    - is for numeric. Note, that this would convert

    $5,423.98 for US and others who has "." as a decimal delimiter
    $5.423,98 for Europe and others who has "," as decimal delimiter
    Alexey Smirnov, Mar 31, 2009
    #7
    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. S.Guhananth
    Replies:
    1
    Views:
    543
    Alvin Bruney [Microsoft MVP]
    Apr 30, 2005
  2. Zyron
    Replies:
    2
    Views:
    1,495
    Jukka K. Korpela
    Nov 8, 2005
  3. Mantic
    Replies:
    3
    Views:
    648
    Benjamin Niemann
    Sep 2, 2006
  4. Keith G Hicks
    Replies:
    3
    Views:
    763
    Keith G Hicks
    Feb 18, 2008
  5. Petr Janda
    Replies:
    2
    Views:
    156
    rretzbach
    Mar 8, 2007
Loading...

Share This Page