C# 计算小数

  private void button2_Click(object sender, EventArgs e)
        {
            double a = 0;
            List<string> list = new List<string>();
            for (int i = 0; i < 100; i++)
            {
                a += 0.1;
                list.Add(a.ToString("#0.0"));
            }
            List<int> list_int = new List<int>();

            for (int i=0;i<list.Count;i++) 
            {
                //var t = list[i];
                //var t1 = Convert.ToInt32(t); //报错// 报错原因 var t1 = Convert.ToInt32("1.1"); //
                list_int.Add((int)Convert.ToDouble(list[i]));
            }

            var t1 = Convert.ToDouble("1.5");
            var t2 = Convert.ToDouble("2.5");
            var t3 = Convert.ToDouble("3.5");

            var t = (int)(t1 + t2 + t3);
            var t0 = (int)t1 + (int)t2 + (int)t3;

            //1.5  2.5  3.5   
            //1...= 1+2+3 = 6;
            //2...=7.5 =7;


        }
    }

posted @ 2019-11-18 15:02  enych  阅读(1963)  评论(0编辑  收藏  举报