C#数据表精度十进制 [英] C# datatable decimal with precision
本文介绍了C#数据表精度十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码将新列添加到数据表:
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?
推荐答案
您不能。但是,当使用 String.Format
函数从表中检索值时,可以设置其格式:
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]);
这篇关于C#数据表精度十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文