[英]How to round all numeric columns of a DataTable to 2 decimal places?
Dim DS_LASSummary As New DataSet
DS_LASSummary = Nbfcweb.GetReceivablesForLAS(txtLASAcctno.Text, CmbBankEntryType.Text.Trim)
現在,DS_LASSummary可以具有n個數字列。 我想將每個數字列四舍五入到小數點后兩位。 我無法對列的名稱或索引進行硬編碼。
我不認為可以更改特定數據表的數據類型。 那我有什么選擇呢?
不確定,您不能使用Math.Round以下內容可能會起作用。 也不確定語法。
foreach (DataRow drRow in DS_LASSummary.Rows)
{
for(int i = 0; i < DS_LASSummary.Columns.Count; i++)
{
int rowValue;
if (int.TryParse(drRow[i].ToString(), out rowValue))
{
drRow[i] = Math.Round(rowValue, 2);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.