2015-09-05 75 views
0

我在這裏有一個代碼,但AttendancePercentage中的輸出不斷將結果轉換爲整數。c#datagridview需要輸出單元格中的十進制值

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

回答

0

試試這個,

dataGridView1.Columns['Column Number'].DefaultCellStyle.Format = "0.00##"; 

在這裏添加您正確的列數: **Columns['Column Number']**

+0

錯誤說。 「它不是定義DefaultCellStyle」 –

+0

嘗試將其應用於整列 – iJay

+0

如果您嘗試設置單元格格式,則這是在行模板中完成的,而不是在行中完成。 –

相關問題