[英]c# datagridview need to output decimal value in a cell
我在這里有一個代碼,但是AttendancePercentage中的輸出不斷將結果轉換為整數。
A1 = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
A2 = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
decimal grade = (((A1 + A2) / (decimal)2) * 50) + 50;
double AttendancePercentage = (double)grade * (double).05;
dataGridView1.Rows[e.RowIndex].Cells[19].Value = grade;
dataGridView1.Rows[e.RowIndex].Cells[20].Value = AttendancePercentage;
假設A1 = 1且A2 =0。所以我需要輸出3.75,但單元格給出4。
嘗試這個,
dataGridView1.Columns['Column Number'].DefaultCellStyle.Format = "0.00##";
在此處添加正確的列號: **Columns['Column Number']**
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.