Currency Formatting

Discussion in 'ASP .Net' started by Vlad, May 25, 2004.

  1. Vlad

    Vlad Guest

    Hi,

    I am trying to display a currency value formated according to the current
    culture in ASP.NET:
    decimal x = 125345.54M;
    string currencyString = String.Format("{0:c}",x);
    what gets retured is 125,345.54 without the currency symbol of $

    I checked and re-checked my regional settings and tried it on other PCs
    without success...

    When I put a breakpoint and view the following in the Immediate window I see
    that the AnsiCurrencySymbol is null and the CurrencySymbol is "" for some
    reason:
    System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat

    {System.Globalization.NumberFormatInfo}

    System.Object: {System.Globalization.NumberFormatInfo}
    ansiCurrencySymbol: null
    AnsiCurrencySymbol: null
    CurrencyDecimalDigits: 2
    currencyDecimalDigits: 2
    CurrencyDecimalSeparator: "."
    currencyDecimalSeparator: "."
    currencyGroupSeparator: ","
    CurrencyGroupSeparator: ","
    CurrencyGroupSizes: {Length=1}
    currencyGroupSizes: {Length=1}
    CurrencyNegativePattern: 0
    currencyNegativePattern: 0
    CurrencyPositivePattern: 0
    currencyPositivePattern: 0
    CurrencySymbol: ""
    currencySymbol: ""
    CurrentInfo: {System.Globalization.NumberFormatInfo}
    InvariantInfo: {System.Globalization.NumberFormatInfo}
    invariantInfo: {System.Globalization.NumberFormatInfo}
    IsReadOnly: false
    isReadOnly: false
    m_dataItem: 41
    m_useUserOverride: true
    NaNSymbol: "NaN"
    nanSymbol: "NaN"
    negativeInfinitySymbol: "-Infinity"
    NegativeInfinitySymbol: "-Infinity"
    NegativeSign: "-"
    negativeSign: "-"
    NumberDecimalDigits: 2
    numberDecimalDigits: 2
    NumberDecimalSeparator: "."
    numberDecimalSeparator: "."
    NumberGroupSeparator: ","
    numberGroupSeparator: ","
    NumberGroupSizes: {Length=1}
    numberGroupSizes: {Length=1}
    numberNegativePattern: 1
    NumberNegativePattern: 1
    PercentDecimalDigits: 2
    percentDecimalDigits: 2
    percentDecimalSeparator: "."
    PercentDecimalSeparator: "."
    PercentGroupSeparator: ","
    percentGroupSeparator: ","
    percentGroupSizes: {Length=1}
    PercentGroupSizes: {Length=1}
    PercentNegativePattern: 0
    percentNegativePattern: 0
    percentPositivePattern: 0
    PercentPositivePattern: 0
    percentSymbol: "%"
    PercentSymbol: "%"
    PerMilleSymbol: "?"
    perMilleSymbol: "?"
    PositiveInfinitySymbol: "Infinity"
    positiveInfinitySymbol: "Infinity"
    positiveSign: "+"
    PositiveSign: "+"
    validForParseAsCurrency: true
    validForParseAsNumber: true

    I thought that the CurrentCultureInfo takes its information from the
    regional settings of the PC...

    Please help!

    Thanks,

    Vlad
     
    Vlad, May 25, 2004
    #1
    1. Advertising

  2. Vlad

    Vlad Guest

    Please disregard...
    "Vlad" <> wrote in message
    news:#...
    > Hi,
    >
    > I am trying to display a currency value formated according to the current
    > culture in ASP.NET:
    > decimal x = 125345.54M;
    > string currencyString = String.Format("{0:c}",x);
    > what gets retured is 125,345.54 without the currency symbol of $
    >
    > I checked and re-checked my regional settings and tried it on other PCs
    > without success...
    >
    > When I put a breakpoint and view the following in the Immediate window I

    see
    > that the AnsiCurrencySymbol is null and the CurrencySymbol is "" for some
    > reason:
    > System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat
    >
    > {System.Globalization.NumberFormatInfo}
    >
    > System.Object: {System.Globalization.NumberFormatInfo}
    > ansiCurrencySymbol: null
    > AnsiCurrencySymbol: null
    > CurrencyDecimalDigits: 2
    > currencyDecimalDigits: 2
    > CurrencyDecimalSeparator: "."
    > currencyDecimalSeparator: "."
    > currencyGroupSeparator: ","
    > CurrencyGroupSeparator: ","
    > CurrencyGroupSizes: {Length=1}
    > currencyGroupSizes: {Length=1}
    > CurrencyNegativePattern: 0
    > currencyNegativePattern: 0
    > CurrencyPositivePattern: 0
    > currencyPositivePattern: 0
    > CurrencySymbol: ""
    > currencySymbol: ""
    > CurrentInfo: {System.Globalization.NumberFormatInfo}
    > InvariantInfo: {System.Globalization.NumberFormatInfo}
    > invariantInfo: {System.Globalization.NumberFormatInfo}
    > IsReadOnly: false
    > isReadOnly: false
    > m_dataItem: 41
    > m_useUserOverride: true
    > NaNSymbol: "NaN"
    > nanSymbol: "NaN"
    > negativeInfinitySymbol: "-Infinity"
    > NegativeInfinitySymbol: "-Infinity"
    > NegativeSign: "-"
    > negativeSign: "-"
    > NumberDecimalDigits: 2
    > numberDecimalDigits: 2
    > NumberDecimalSeparator: "."
    > numberDecimalSeparator: "."
    > NumberGroupSeparator: ","
    > numberGroupSeparator: ","
    > NumberGroupSizes: {Length=1}
    > numberGroupSizes: {Length=1}
    > numberNegativePattern: 1
    > NumberNegativePattern: 1
    > PercentDecimalDigits: 2
    > percentDecimalDigits: 2
    > percentDecimalSeparator: "."
    > PercentDecimalSeparator: "."
    > PercentGroupSeparator: ","
    > percentGroupSeparator: ","
    > percentGroupSizes: {Length=1}
    > PercentGroupSizes: {Length=1}
    > PercentNegativePattern: 0
    > percentNegativePattern: 0
    > percentPositivePattern: 0
    > PercentPositivePattern: 0
    > percentSymbol: "%"
    > PercentSymbol: "%"
    > PerMilleSymbol: "?"
    > perMilleSymbol: "?"
    > PositiveInfinitySymbol: "Infinity"
    > positiveInfinitySymbol: "Infinity"
    > positiveSign: "+"
    > PositiveSign: "+"
    > validForParseAsCurrency: true
    > validForParseAsNumber: true
    >
    > I thought that the CurrentCultureInfo takes its information from the
    > regional settings of the PC...
    >
    > Please help!
    >
    > Thanks,
    >
    > Vlad
    >
    >
     
    Vlad, May 25, 2004
    #2
    1. Advertising

  3. Hi Vlad,

    Generally in .net application, we can set the globalication's culture info
    of the current Context via
    System.Thread.CurrentThread.CurrentCulture or
    System.Thread.CurrentThread.CurrentUICulture
    the former is for date and currency's localization formatting
    and the latter is for UI's localization

    So wecan set the appropricate culture value to the
    System.Thread.CurrentThread.CurrentCulture
    before doing currency or date formatting. such as:

    private void Page_Load(object sender, System.EventArgs e)
    {
    System.Threading.Thread.CurrentThread.CurrentCulture = new
    System.Globalization.CultureInfo("zh-CN");
    decimal dec = 4343.34343434M;
    Response.Write( String.Format("{0:c}",dec));

    }

    In addition, the following reference in MSDN contains more description on
    this:

    #Formatting Numeric Data for a Specific Culture
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconformattingnumericd
    ataforspecificculture.asp?frame=true

    Hope also helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], May 26, 2004
    #3
  4. Vlad

    Vlad Guest

    Thanks for replying...
    As I stated in my previous post this issue should have been disregarded
    since I found that one of the developers resets the currency symbol to "" in
    the BasePage that every page in our application inherits from.

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Vlad,
    >
    > Generally in .net application, we can set the globalication's culture info
    > of the current Context via
    > System.Thread.CurrentThread.CurrentCulture or
    > System.Thread.CurrentThread.CurrentUICulture
    > the former is for date and currency's localization formatting
    > and the latter is for UI's localization
    >
    > So wecan set the appropricate culture value to the
    > System.Thread.CurrentThread.CurrentCulture
    > before doing currency or date formatting. such as:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > System.Threading.Thread.CurrentThread.CurrentCulture = new
    > System.Globalization.CultureInfo("zh-CN");
    > decimal dec = 4343.34343434M;
    > Response.Write( String.Format("{0:c}",dec));
    >
    > }
    >
    > In addition, the following reference in MSDN contains more description on
    > this:
    >
    > #Formatting Numeric Data for a Specific Culture
    >

    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconformattingnumericd
    > ataforspecificculture.asp?frame=true
    >
    > Hope also helps. Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    >
     
    Vlad, May 26, 2004
    #4
    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. ashish

    currency formatting for Euro

    ashish, Apr 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    456
    ashish
    Apr 27, 2004
  2. CD1
    Replies:
    7
    Views:
    5,636
  3. Daniele Varrazzo

    Formatting Currency According to Locale

    Daniele Varrazzo, Apr 28, 2004, in forum: Python
    Replies:
    0
    Views:
    314
    Daniele Varrazzo
    Apr 28, 2004
  4. pebelund
    Replies:
    1
    Views:
    434
    Morten Wennevik
    Oct 23, 2006
  5. RCM
    Replies:
    0
    Views:
    862
Loading...

Share This Page