This commit is contained in:
GukSang.Jin
2026-01-06 11:33:44 +08:00
parent c4a9162499
commit b1c3e2781b

View File

@@ -254,12 +254,31 @@ namespace WindowsFormsApp6
{ {
if (e.RowIndex < 0 || e.ColumnIndex == 0) return; // 跳过序号列 if (e.RowIndex < 0 || e.ColumnIndex == 0) return; // 跳过序号列
// 获取当前行的序号,判断是否是标准偏差行
string rowName = "";
if (e.RowIndex < dataGridView1.Rows.Count)
{
var row = dataGridView1.Rows[e.RowIndex];
if (row.Cells["序号"].Value != null)
{
rowName = row.Cells["序号"].Value.ToString();
}
}
// 格式化数值显示为2位小数 // 格式化数值显示为2位小数
if (e.Value != null && e.Value != DBNull.Value) if (e.Value != null && e.Value != DBNull.Value)
{ {
if (double.TryParse(e.Value.ToString(), out double numValue)) if (double.TryParse(e.Value.ToString(), out double numValue))
{ {
// 如果值为0或接近0显示为空白 // 标准偏差行即使为0也要显示
if (rowName == ROW_STD_DEVIATION)
{
e.Value = numValue.ToString("F2");
e.FormattingApplied = true;
return;
}
// 其他行如果值为0或接近0显示为空白
if (Math.Abs(numValue) < 0.001) if (Math.Abs(numValue) < 0.001)
{ {
e.Value = ""; e.Value = "";