2
schangxiang@126.com
2024-06-26 3fc83007da4ba3442254bf36db0753514a0df1b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
using iWare_SCADA_Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWare_SCADA_BusinessLogical.Utils
{
    /// <summary>
    /// 系统帮助类
    /// </summary>
    public class SystemHelper
    {
        /// <summary>
        /// 字符串转换decimal类型
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static decimal GetDecimal(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return 0;
            }
            decimal decimalValue = 0;
            var isRight = decimal.TryParse(value, out decimalValue);
            if (isRight)
            {
                return decimalValue;
            }
            return 0;
        }
 
        /// <summary>
        /// decimal集合计算平均值
        /// </summary>
        /// <param name="valueList">集合</param>
        /// <param name="digits">精度</param>
        /// <returns></returns>
        public static string CalcDecimalAvg(List<decimal> valueList, int digits)
        {
            var sum = valueList.Sum();
            var count = valueList.Count;
            var bb = Convert.ToDecimal((sum / (decimal)count).ToString("f" + digits.ToString()));
            return bb.ToString();
        }
 
    }
}