zoukankan      html  css  js  c++  java
  • 页码数pageSize

    //先设定好一页有多大的Size
    int pagesize = 100;
    //(总的Count数)÷pagesize==>之后的结果再向上取整Math.Ceiling
    Math.Ceiling(0.4) //1
    Math.Ceiling(0.5) //1
    Math.Ceiling(0.6) //1
    //这样就知道有多少"页"
    int pagenum = Convert.ToInt32(Math.Ceiling((double)skus.Count/ pagesize));
    //然后就可以每一页每一页的进行操作了,操作完一页就换下一页
    for (int i = 0; i < pagenum; i++)
        {
          var tempsku = skus.Skip(i * pagesize).Take(pagesize);
          XDocument obj = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
          //构造根节点
          obj.Add(new XElement("request",
                  new XElement("criteriaList", tempsku.Select(l => 
                                new XElement("criteria",
                                new XElement("ff", ff),
                                new XElement("aa", aa),
                                new XElement("bb", l.sku),
                                new XElement("cc", ""))))));
          XmlDocument doc = new XmlDocument();
          doc.LoadXml(obj.ToString());
          //拼接url
          string url = GenerateUrl("xxx", appkey, whse, apiurl, secret, doc, timestamp);
          var result = this.Post(url, doc); 
       }

    C#取整函数Math.Round、Math.Ceiling和Math.Floor

    1.Math.Round(圆形的,球形的):四舍六入五取偶

    Math.Round(0.0) //0
    Math.Round(0.4) //0
    Math.Round(0.5) //0
    Math.Round(0.6) //1
    Math.Round(0.7) //1

    说明:对于1.5,因要返回偶数,所以结果为2。

    2.Math.Ceiling(天花板,向上取整):只要有小数都加1

    Math.Ceiling(0.0) //0
    Math.Ceiling(0.4) //1
    Math.Ceiling(0.5) //1
    Math.Ceiling(0.6) //1
    Math.Ceiling(0.7) //1

    说明:例如在分页算法中计算分页数很有用。

    3.Math.Floor(地板,向下取整):总是舍去小数

    Math.Floor(0.0) //0
    Math.Floor(0.4) //0
    Math.Floor(0.5) //0
    Math.Floor(0.6) //0
    Math.Floor(0.7) //0
    人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。
  • 相关阅读:
    hdu 2485 Destroying the bus stations 迭代加深搜索
    hdu 2487 Ugly Windows 模拟
    hdu 2492 Ping pong 线段树
    hdu 1059 Dividing 多重背包
    hdu 3315 My Brute 费用流,费用最小且代价最小
    第四天 下载网络图片显示
    第三天 单元测试和数据库操作
    第二天 布局文件
    第一天 安卓简介
    Android 获取存储空间
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/14472991.html
Copyright © 2011-2022 走看看