.net根据数据库公式计算结果

 DataTable dt = new DataTable();

            String ev_A = 5.88.ToString();
            String ev_B = 2.ToString();
            String ev_C = 4.ToString();
            String ev_W = 10.ToString();

            String expression = "a+(w-b)*c";

            expression = expression.Replace("a", ev_A);
            expression = expression.Replace("b", ev_B);
            expression = expression.Replace("c", ev_C);
            expression = expression.Replace("w", ev_W);


            decimal result=Convert.ToDecimal(dt.Compute(expression,""));

            Console.WriteLine(Math.Round(result,2));
            Console.ReadKey();

  

posted @ 2018-06-26 11:11  唔愛吃蘋果  阅读(172)  评论(0编辑  收藏  举报