常用数字处理小技巧2011-03-05说明: 平时编程中总会遇到数字处理问题, 这里将自己平时总结的一些数字处理小技巧结合MSDN上相关的介绍, 列举一些常用的数字处理技术.原理非常简单, 不再细说, 只图自己和大家引用或参考时方便.1.对计算结果四舍五入(d:数,i小数位数)效果: 233.8763--> 233.88计算结果四舍五入CODE
     //d: 表示四舍五入的数字; i: 保留的小数位数
     public static double Round(double d, int i)
     {
       if (d >= 0)
       {
         d += 5 * Math.Pow(10, -(i + 1));
       }
       else
       {
         d += -5 * Math.Pow(10, -(i + 1));
       }
       string str = d.ToString();
       string[] strs = str.Split(".");
       int idot = str.IndexOf(".");
       string prestr = strs[0];
       string poststr = strs[1];
       if (poststr.Length > i)
       {
         poststr = str.Substring(idot + 1, i);//截取需要位数
       }
       if (poststr.Length <= 2)
       {
         poststr = poststr + "0";
       }
       string strd = prestr + "." + poststr;
       d = Double.Parse(strd);//将字符串转换为双精度实数
       return d;
     }2.将商品金额小写转换成大写效果: 1234566789-->壹拾贰亿叁仟肆佰伍拾陆万陆仟柒佰捌拾玖元将金额小写转化为大写CODE
     private void Convert_Click(object sender, EventArgs e)
     {
       String[] Scale = { "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };
       String[] Base = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
       String Temp = textBox1.Text.ToString();
       String Info = null;
       int index = Temp.IndexOf(".", 0, Temp.Length);//判断是否有小数点
       if (index != -1)
       {
         Temp = Temp.Remove(Temp.IndexOf("."), 1);
         for (int i = Temp.Length; i > 0; i--)
         {
           int Data = Convert.ToInt16(Temp[Temp.Length - i]);
           Info += Base[Data - 48];
           Info += Scale[i - 1];
         }
       }
       else
       {
         for (int i = Temp.Length; i > 0; i--)
         {
           int Data = Convert.ToInt16(Temp[Temp.Length - i]);
           Info += Base[Data - 48];
           Info += Scale[i + 1];
         }
       }
       textBox2.Text = Info;
     }