请教高手:现在有这样一个需求.
比如有一个内存的数据表,有三个列,一个是单价,一个是数量,一个是金额(另外还有一个是序号)现在有这样一个需求,就是计算金额时,如果有小数,就向上取得121.10就是122,121.90也是122.
DataTable dt = new DataTable();
dt.Columns.Add("price",typeof(decimal));
dt.Columns.Add("count",typeof(decimal));
dt.Coumuns.Add("money",typeof(int),"price*count"));
这样写好了之后,就发现,它自动的进行了四舍五入的处理了.
不知道这样的表表达式如何写.谢谢!

解决方案 »

  1.   

    写一个for循环,在这个for循环中在嵌套一个for循环来分别读取datatable中的每一个值,然后把这个值转换为字符串,通过字符串的Indexof(".")方法来判断是否是小数,如果返回值为-1证明不是小数,如果不等于-1的时候证明是小数,这时通过字符串的remove方法把小数点后面的数字给删除,列如:string aaaa = "123.23";通过int i = Convert.ToInt32(aaa.Remove(aaa.IndexOf("."),aaa.Length-aaa.IndexOf(".")));这句代码得出的i的值为123,这时在把这个数加一就是你要的数啦,然后给它保存在表中就可以了
      

  2.   

    v = "IIF(Convert(({0}),'System.Int32')>({0}),Convert(({0}),'System.Int32'),IIF(Convert(({0}),'System.Int32')=({0}),convert(({0}),'System.Int32'),Convert(({0}),'System.Int32')+1))";