I have this code to add new column to datatable:
DataColumn col = new DataColumn("column", typeof(decimal)); col.Caption = "Column"; mytable.Columns.Add(col);
How can I specify decimal precision for this column so the value will always be in the format I want it to be?
You can not. However, you can format the value when you retrieve it from the table using String.Format
function:
String.Format("{0:0.##}", (Decimal) myTable.Rows[rowIndex].Columns[columnIndex]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With