8月记录点点:

 

1.四舍五入(控制小数点)

输入一个数,点击button  就弹出一个对话框,里面是已经四舍五入好的数字,如12.595  或者  12.6  或者  12.54  或者  12.553  或者  12
输出结果  12.60    12.60    12.54     12.55   12.00

代码:
double txtnum = Convert.ToDouble(this.textBox1.Text);
            if (txtnum < 0)
            {
                txtnum = Math.Round(txtnum + 5 / Math.Pow(10, 3), 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                txtnum = Math.Round(Convert.ToDouble(txtnum), 2, MidpointRounding.AwayFromZero);
            }
            MessageBox.Show(txtnum.ToString());

2.c# 查找一个字符串在另一个字符串出现的次数]的巧妙做法
string test = "good good study day day up";
        string r = test.Replace("oo","");
        int num = (test.Length - r.Length) /2;
        Response.Write(num);//num为"oo"在test字符串中出现的次数

3.让sql语句查询结果默认排序,按照in语句的顺序返回结果
例:select productId,shop_type from T_Info_Product where productId in(83,56,14,13,11) and product_status=1  Order by CharIndex( cast(productId as nvarchar(30)),'83,56,14,13,11')

原文地址:https://www.cnblogs.com/mhker/p/3330483.html