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"