Пример #1
0
        /// <summary>
        /// 参数说明
        /// value:修约的数值
        /// precision:0表示保留到整数,-1表示保留一位小数,-2标书保留两位小数
        /// roundRule:0表示四舍六入五单双,0.2表示0.2修约,0.5表示0.5修约
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public override object Evaluate(object[] args)
        {
            double value     = 0;
            int    precision = 1;
            string roundRule = "0";
            double r         = 0;

            try
            {
                value     = ArgumentConvert.ToDouble(args[0]);
                precision = ArgumentConvert.ToInt(args[1]);
                roundRule = ArgumentConvert.ToString(args[2]);

                switch (roundRule)
                {
                case "0":
                    r = numericalRound.Evaluate(value, precision);
                    break;

                case "0.2":
                    r = numericalRound02.Evaluate(value, precision);
                    break;

                case "0.5":
                    r = numericalRound05.Evaluate(value, precision);
                    break;
                }

                return(NumericalFormatProvier.Format(r, precision));
            }
            catch
            {
                return(CalcError.Value);
            }
        }
        public override object Evaluate(object[] args)
        {
            try
            {
                DateTime start_date = ArgumentConvert.ToDateTime(args[0]);
                DateTime end_date   = ArgumentConvert.ToDateTime(args[1]);
                String   type       = ArgumentConvert.ToString(args[2]).Trim().ToUpper();
                //int hasDecimal = CalcConvert.ToInt(args[3]);

                double   time = 0;
                TimeSpan ts   = end_date.Subtract(start_date);
                switch (type)
                {
                case "D":    //天数
                    time = ts.TotalDays;
                    break;

                case "H":    //小时数
                    time = (ts.TotalHours < 0 ? ts.TotalHours + 24 : ts.TotalHours);
                    break;

                case "M":    //分钟数
                    time = (ts.TotalMinutes < 0 ? ts.TotalMinutes + 24 * 60 : ts.TotalMinutes);
                    break;

                case "S":    //秒数
                    time = (ts.TotalSeconds < 0 ? ts.TotalSeconds + 24 * 3600 : ts.TotalSeconds);
                    break;
                }

                if (time != 0)
                {
                    return(time);
                }
                return(DBNull.Value);
            }
            catch
            {
                throw new InvalidCastException();
            }
        }