Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 转换为十进制问题读取逗号时出错_C#_.net - Fatal编程技术网

C# 转换为十进制问题读取逗号时出错

C# 转换为十进制问题读取逗号时出错,c#,.net,C#,.net,我在计算一个值。事实上,当我取excel的值(值为3.666)时,我的字符串将其读取为3.666,当我将其转换为十进制时,visual将其读取为3666,因为excel中的点不是小数。我怎么能告诉他那是个逗号 List<MappedCsv> LFridays = ValorAperturaEnBolsa(); Decimal ValorApertura; Decimal nAccionesDia; Decimal nAccionesTotal = 0; foreach(Mapped

我在计算一个值。事实上,当我取excel的值(值为3.666)时,我的字符串将其读取为3.666,当我将其转换为十进制时,visual将其读取为3666,因为excel中的点不是小数。我怎么能告诉他那是个逗号

List<MappedCsv> LFridays = ValorAperturaEnBolsa();
Decimal ValorApertura;
Decimal nAccionesDia;
Decimal nAccionesTotal = 0;

foreach(MappedCsv MC in LFridays)
{
    ValorApertura = Convert.ToDecimal(MC.Apertura);
    nAccionesDia = 49 / ValorApertura;
    nAccionesDia = Math.Round(nAccionesDia, 3);
    nAccionesTotal += nAccionesDia;
}

如果字符串始终包含“.”作为十进制分隔符,请使用

ValorApertura = Convert.ToDecimal(MC.Apertura, CultureInfo.InvariantCulture);

只需将正确的CultureInfo传递给@KlausGütter,我该怎么做?MC.Apertura的值是否返回类似于3.666的字符串?您还可以更改excel设置,将点设置为十进制sperator@Zingers是,字符串值为3.666