利用InvariantCulture
Double _Test = Convert.ToDouble(Test,CultureInfo.InvariantCulture);
编辑:我相信您当前的文化是 "German" de-DE
,它,
用于浮点。
尝试了以下代码。您也可以NumberFormatInfo.InvariantInfo
在转换期间使用。
string Test = "17828.571428571";
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
double d = Convert.ToDouble(Test);
double d2 = Convert.ToDouble(Test, CultureInfo.InvariantCulture);
double d3 = Convert.ToDouble(Test, NumberFormatInfo.InvariantInfo);
string Test2 = "17828,571428571"; //Notice the comma in the string
double d4 = Convert.ToDouble(Test2);
Console.WriteLine("Using comma as decimal point: "+ d4);
输出:(注意输出中的逗号)
Wihtout Invariant: 17828571428571
With InvariantCulture: 17828,571428571
With NumberFormatInfo.InvariantInfo: 17828,571428571
Using comma as decimal point: 17828,571428571