1

I'd like to get the currency symbol used by Windows; this symbol can be viewed and modified using the Region and Language option from the control panel.

RegionInfo.CurrentRegion represents the regional information of the language used in the current thread; RegionInfo.CurrentRegion.CurrencySymbol therefore will not necessarily match the currency symbol as selected by the user of the operating system.

If I modify just the currency symbol in Region and Language > Advanced settings... > Currency, I'd like to be able to access that symbol from a C# program. How can this be done?

Thank you for reading my post.

5 Answers 5

3

The RegionInfo does not reflect user-changed settings. I think something like

CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol

will work.

ADDITION (after answer was accepted):

I tested a bit, and it seems that in some cases RegionInfo does reflect user-settings. Even though the spec says: In contrast to CultureInfo, RegionInfo does not represent preferences of the user and does not depend on the user's language or culture.

On my Windows 7 pc, I get this result: RegionInfo does reflect the user-settings, even if I construct a new instance of RegionInfo (rather than using the CurrentRegion getter). So now we're confused.

5
  • Thank you for the update. It seems that you have similar results as @André Christoffer Andersen. I tested both answers using two different projects (the one I actually work in and one I created just to test the results); in both cases your answer gives me exactly what I need even after multiple changes to the Region and Language settings. RegionInfo consistently gives me the correct currency symbol associated with the culture of the running thread regardless of the OS settings.
    – Pooven
    Aug 16, 2012 at 19:01
  • @Pooven Interesting. What version of the .NET Framework and Visual Studio do you use? Maybe they changed something. Aug 17, 2012 at 5:29
  • That's a good point. I'm using .NET 3.5 SP1 with Visual Studio 2008 V9 SP.
    – Pooven
    Aug 17, 2012 at 6:43
  • I used VS2010 and .NET 4 SP1. I wonder if that's the reason. Maybe under some conditions the runtime does not have permissions to access the user preferences? I guess you weren't changing the settings while your application was already running? Aug 17, 2012 at 7:23
  • It does make sense for RegionInfo to provide user elected regional settings. It does seem more reasonable for the CurrentCulture to provide the user's customized regional settings. If I change the currency symbol while my application is running, CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol does not return the change; but this isn't necessarily undesired. Thank you once again for taking the time to test this :)
    – Pooven
    Aug 23, 2012 at 9:31
2

It can be found inside of RegionInfo.CurrencySymbol

2
  • That does not exist w/o getting an instance first.
    – ℍ ℍ
    Aug 16, 2012 at 14:30
  • @HenkHolterman - I linked MSDN for such details. This should work fine. Aug 16, 2012 at 14:39
1

Are you sure your original assumptions are right? When I change/edit the currency symbol under "Region and Language > Additional settings > Currency > Currency symbol"

The following changes according:

RegionInfo.CurrentRegion.CurrencySymbol
1
  • 1
    That's interesting; my original assumption, while based on the documentation, was also based on observation. I did modify the Windows currency symbol manually and RegionInfo.CurrencySymbol did not update accordingly. I don't understand how we could be experiencing different behaviour? Thank you for taking the time to try this out, I appreciate your response :)
    – Pooven
    Aug 16, 2012 at 14:56
0

Here's some gotchas I learned today - my code verifying my findings is below. I set my system to Spanish - Dominican Republic, and changed the currency symbol from "RD$" to "$". I then set my culture/UI culture to es-DO instead of en-US.

  • Using number.ToString("C2") does not follow user-customized settings. So, if you set System.Globalization.CultureInfo.CurrentCulture/CurrentUICulture to es-DO and do 1.00M.ToString("C2"), it will return RD$1.00.

  • To have it actually use the user-customized settings, you have to have a var info = new CultureInfo("es-DO") variable and then use string.Format(info, "{0:C2}", 1.00M) to get the expected $1.00, as per the change above.

  • You cannot use string.Format(CultureInfo.CurrentCulture, "{0:C2}", 1.00M) as it will not return user customizations - in this case, it would return RD$1.00.

I think this is silly, but if someone out there knows the real reason behind for this behavior, please share as I am curious.

Here's the code for repro:

var esdo = new CultureInfo("en-US");
{en-US}
esdo = new CultureInfo("es-DO");
{es-DO}
var resdo = new RegionInfo("es-DO");
{es-DO}
        CurrencyEnglishName: "Dominican Peso"
        CurrencyNativeName: "Peso"
        CurrencySymbol: "$"
        DisplayName: "Dominican Republic"
        EnglishName: "Dominican Republic"
        GeoId: 65
        IsMetric: true
        ISOCurrencySymbol: "DOP"
        Name: "es-DO"
        NativeName: "República Dominicana"
        ThreeLetterISORegionName: "DOM"
        ThreeLetterWindowsRegionName: "DOM"
        TwoLetterISORegionName: "DO"
esdo.NumberFormat
{System.Globalization.NumberFormatInfo}
        CurrencyDecimalDigits: 2
        CurrencyDecimalSeparator: "."
        CurrencyGroupSeparator: ","
        CurrencyGroupSizes: {int[1]}
        CurrencyNegativePattern: 1
        CurrencyPositivePattern: 0
        CurrencySymbol: "$"
        DigitSubstitution: None
        IsReadOnly: false
        NaNSymbol: "NeuN"
        NativeDigits: {string[10]}
        NegativeInfinitySymbol: "-Infinito"
        NegativeSign: "-"
        NumberDecimalDigits: 2
        NumberDecimalSeparator: "."
        NumberGroupSeparator: ","
        NumberGroupSizes: {int[1]}
        NumberNegativePattern: 1
        PercentDecimalDigits: 2
        PercentDecimalSeparator: "."
        PercentGroupSeparator: ","
        PercentGroupSizes: {int[1]}
        PercentNegativePattern: 1
        PercentPositivePattern: 1
        PercentSymbol: "%"
        PerMilleSymbol: "‰"
        PositiveInfinitySymbol: "Infinito"
        PositiveSign: "+"
var dsa = 1.00M;
string.Format(esdo,"{0:C2}",dsa)
"$1.00"
dsa.ToString("C2")
"RD$1.00"
string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0:C2}",dsa)
"RD$1.00"
string.Format(System.Globalization.CultureInfo.CurrentUICulture,"{0:C2}",dsa)
"RD$1.00"
System.Globalization.CultureInfo.CurrentUICulture
{es-DO}
string.Format(esdo,"{0:C2}",dsa)
"$1.00"
-1
//    Do something like that maybe
public static string getSeparator()
        {
            string output = string.Empty;
            try
            {
                RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("International");
                output = reg.GetValue(EnumClass.String.sList.ToString(), output).ToString();

                reg.Dispose();
            }`enter code here`
            catch (Exception ie)
            {
                // catch error
            }
            return output;
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.