如何在Datagridview中舍入double类型的值

时间:2017-09-20 19:42:23

标签: c# datagridview

我想知道如何将双重类型的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);
}

1 个答案:

答案 0 :(得分:0)

您应该将值设置为变量:

   nareaColumn = Math.Round(nareaColumn, 2);