Reputation: 101
I'm doing a calculation to know a value. The fact is that when I take the value of an excel which value is 3.666 (and my string reads it as 3.666) the visual reads it as 3666 when I convert it to decimal since the point in excel is not for decimals. How can I tell him that's a comma?
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;
}
Upvotes: 0
Views: 140
Reputation: 12032
If the string always contains a '.' as decimal separator, convert it using
ValorApertura = Convert.ToDecimal(MC.Apertura, CultureInfo.InvariantCulture);
Upvotes: 1