I have the following C# code that reads in data from a datatable (which was original constructed from an Excel spreadsheet)
private byte GetVal(DataRow dataRow, string caption)
{
var val = dataRow.GetValue(caption).ToString().Trim();
if (!String.IsNullOrEmpty(val))
{
return (byte)(Decimal.Parse(val) * 100);
}
return (byte)0;
}
this is blowing up because there is value of: “5.5555555555555552E-2” reading in from one of the cells (the val variable)
its blowing up on this line:
return (byte)(Decimal.Parse(val) * 100);
with the error: Input string was not in a correct format.
What is the best way to work around this so i can read in the value?
Try this:
Decimal.Parse Method (String, NumberStyles, IFormatProvider)NumberStyles.AllowExponent (
AllowExponentis a subset ofNumberStyles.Float)