【发布时间】:2018-03-02 00:24:44
【问题描述】:
我想知道如何将 double 类型的 Datatable 值四舍五入为两位小数,我尝试了以下方法,但它们都对我不起作用,我做错了什么吗?
{ DataRow newRow = informationTable.NewRow();
string typeColumn = material.Name.Replace(',', ':');// store element Id value
double gvolColumn = quantity.GrossVolume;// store gross volume value
double nvolColumn = quantity.NetVolume;// store net`enter code here` volume value
double gareaColumn = quantity.GrossArea;// store gross area value
double nareaColumn = quantity.NetArea;// store net area value
String.Format("{0:0.00}", gvolColumn);
String.Format("{0:0.00}", nvolColumn);
String.Format("{0:0.00}", gareaColumn);
Math.Round(nareaColumn, 2);
// set the relative information of current element into the table.
newRow["Element Type"] = typeColumn;
newRow["Gross volume"] = gvolColumn;
newRow["Net volume"] = nvolColumn;
newRow["Gross area"] = gareaColumn;
newRow["Net area"] = nareaColumn;
informationTable.Rows.Add(newRow);
}
【问题讨论】:
-
您要舍入还是只显示截断的值?
-
是的,只是为了简单地显示@Nikolaus
-
我检查了那个解决方案,但对我不起作用@HaveSpacesuit
标签: c# datagridview