C# 转换为十进制问题读取逗号时出错
我在计算一个值。事实上,当我取excel的值(值为3.666)时,我的字符串将其读取为3.666,当我将其转换为十进制时,visual将其读取为3666,因为excel中的点不是小数。我怎么能告诉他那是个逗号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
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