decimal d2 = 0.0000002500m;
Console.WriteLine(d2.ToString());
double d3 = 0.0000002500;
Console.WriteLine(d3.ToString());
输出结果是,
0.0000002500
2.5E-07
double在ToString的时候,直接进行了科学计数法。
DataTable dataTable = new DataTable(); DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = "column1"; dataColumn.DataType = typeof(decimal); dataTable.Columns.Add(dataColumn); DataColumn dataColumn2 = new DataColumn(); dataColumn2.ColumnName = "column2"; dataColumn2.DataType = typeof(decimal); dataTable.Columns.Add(dataColumn2); decimal d2 = 0.0000002500m; string value2 = d2.ToString(); Console.WriteLine(value2); double d3 = 0.0000002500; string value3 = d3.ToString(); Console.WriteLine(d3.ToString()); var dataRow = dataTable.NewRow(); try { dataRow["column1"] = value2; } catch (Exception ex) { Console.WriteLine(ex.Message); } dataRow["column2"] = value3; Console.WriteLine(dataRow["column1"]); Console.WriteLine(dataRow["column2"]);
需要把这个代码中的decimal修正为double。或者把数据源,修正为decimal
dataColumn2.DataType = typeof(decimal);