修复温差图例表验证逻辑,在解析浮点数前先去掉单位

This commit is contained in:
zqm
2025-11-10 10:34:46 +08:00
parent 14af230190
commit ae787ed62c

View File

@@ -219,8 +219,11 @@ namespace JoyD.Windows.CS
{ {
string value = e.FormattedValue.ToString().Trim(); string value = e.FormattedValue.ToString().Trim();
// 去掉单位,只保留数字部分
string numericValue = System.Text.RegularExpressions.Regex.Replace(value, @"[^0-9.-]", "");
// 尝试解析输入为浮点数 // 尝试解析输入为浮点数
if (!float.TryParse(value, out float tempValue)) if (!float.TryParse(numericValue, out float tempValue))
{ {
dataGridViewTempDiff.Rows[e.RowIndex].ErrorText = "请输入有效的温度值"; dataGridViewTempDiff.Rows[e.RowIndex].ErrorText = "请输入有效的温度值";
e.Cancel = true; e.Cancel = true;