I have changed Global Application Culture thread for currency number format in (fr-CA) as shown below.
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyPositivePattern = 1;
Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyNegativePattern = 5;
CultureInfo CADCultureref = new CultureInfo("fr-CA");
CADCultureref = Thread.CurrentThread.CurrentCulture;
NumberFormatInfo CADNumFormatref = new NumberFormatInfo();
CADNumFormatref = Thread.CurrentThread.CurrentCulture.NumberFormat;
CADNumFormatref.CurrencyGroupSeparator = ".";
CADNumFormatref.CurrencyDecimalSeparator = ",";
CADCultureref.NumberFormat = CADNumFormatref;
Thread.CurrentThread.CurrentCulture = CADCultureref;
Thread.CurrentThread.CurrentUICulture = CADCultureref;
然后我尝试从货币中解析值,如下所示:
Decimal digit = 1000000;
String currency = digit.ToString("C"); // 1.000.000,00$ (fr-CAD)
decimal parseValue = decimal.Parse(currency , System.Globalization.NumberStyles.Currency | System.Globalization.NumberStyles.Number);
在解析值期间出现异常“{输入字符串格式不正确}”。
由于 CurrentThread 的 Numberformatinfo 中的组分隔符和小数分隔符发生更改,无法解析。
我需要显示“,”来代替“。” 和 ”。” 代替“,”。