Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# datatable decimal with precision

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?

like image 843
Blablablaster Avatar asked May 30 '11 13:05

Blablablaster


1 Answers

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]); 
like image 108
Akram Shahda Avatar answered Sep 30 '22 00:09

Akram Shahda