嗨,我是提前一個C#新手會有人禮貌地告訴我如何這段代碼的值轉換爲雙/圓小數..感謝將翻一番,達到小數點後兩位
DataTable dtValues = new DataTable("GetValues");
strValueNumber = ValueNumber[0].ToString();
dtGetValues = SQLMethods.GetValues(strValueNumber);
total = 0;
for (int i = 0; i < dtValues.Rows.Count; i++)
{
total1 = total1 + Convert.ToInt32(dtGetValues.Rows[i]["total_1"]);
total2 = total2 + Convert.ToDouble(dtGetValues.Rows[i]["total_2l"]) * .45;
tbtotal1.Text = total1.ToString();
tbtotal2.Text = total2.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show("Error in returning selected Values. " +
"Processed with error:" + ex.Message);
}
}
您應該設置循環外的文本框。 'total'被聲明但未被使用。循環前應將total1和total2設爲零。 – MiMo