通过误差来控制数据精度

//话不多说,直接上代码----------看注释就明白        
public static void getSmallFramPoint()
        {
            string framString ="Row,"+"Colum,"+ "framX," + "framY\r\n";
            float i = 15f;
            float j =70f ;
            float a=0;
            float b=0;
            int row = 0;
            int colum = 0;
            int lan = 0;
            int lon = 0;
            for ( i = 15f; i <= 55f; i++)
            {
                lan =Convert.ToInt32(i);
                for (j =70f; j <= 137f; j++)
                {
                    lon = Convert.ToInt32(j) ;
                    for (a = i; a <= i + 1.005f; a += 0.01f)         //0.005用来控制浮点型的误差
                    {
                        row++;
                        for(b=j;b<=j+1.005;b+=0.01f)
                        {
                            colum++;
                            framString += row.ToString() + "," + colum.ToString() + "," + b.ToString("0.00") + "," + a.ToString("0.00") + "\r\n";
                        }
                        colum = 0;
                    }
                    row = 0;
                    //输出
                    System.IO.File.WriteAllText(@"G:\RZPU\20141118fishnet\test\" + lan.ToString() + "-" + lon.ToString() + ".csv", framString);
                    framString = "Row," + "Colum," + "framX," + "framY\r\n";
                    
                }
            }
        }

你可能感兴趣的:(数据)