2 if (numberList.Any()) 3 { 4 exEntity.MinValue = numberList.First().NumberValue.ToString(); 5 exEntity.MaxValue = numberList.Last().NumberValue.ToString(); 6 exEntity.AvgValue = Math.Round((decimal)numberList.Average(p => p.NumberValue), 5).ToString(); 7 //标准差 8 if (numberList.Count > 1) 9 { 10 double sumOfSquare = 0; //平方总和 11 foreach (var item in numberList) 12 { 13 double numberValue = double.Parse(item.NumberValue.ToString()); 14 sumOfSquare += Math.Pow((numberValue - double.Parse(exEntity.AvgValue)), 2); 15 } 16 double stdDeviation = Math.Sqrt(sumOfSquare / (numberList.Count - 1)); 17 stdDeviation = Math.Round(stdDeviation, 5); 18 exEntity.StdDeviation = stdDeviation.ToString(); 19 } 20 }