Search code examples
c#.netdecimalcultureinfoformatexception

C# decimal.Parse() strange FormatException


There is MyDataSet myDataSet with MyTable with column string MyNumber (names changed). Then a row is added to the table (existing code):

decimal d = GetSum();
myDataSet.MyTable.AddMyTableRow(d.ToString("F2"));

Now I have to get that decimal number. But it throws FormatException when I try

decimal.Parse(myDataSet.MyTable[0].MyNumber);
// or
decimal.Parse(myDataSet.MyTable[0].MyNumber, CultureInfo.InvariantCulture);
//or
decimal.Parse(myDataSet.MyTable[0].MyNumber, CultureInfo.CurrentCulture)
//or
anything else..

Solution

  • I solved this by creating additional decimal columns for these numbers.