float和decimal执行效率 (只是代码 没有分析—)

简介: float版:public static void getSmallFramPoint() { string framString ="Row,"+"Colum,"+ "framX," + "framY\r\n"; float ...

float版:

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++;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";
                    
                }
            }
        }
                        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";
                    
                }
            }
        }
 
decimal版:
public static void GetSmallFramPoint(decimal rows,decimal columns,int rowSpan,int columnSpan)
        {
            string framString = "Row," + "Colum," + "framX," + "framY\r\n";
            decimal row=0;
            decimal column=0;
            decimal smallRow = 0;//遍历变量
            decimal smallColumn = 0;//遍历变量
            int lan = 0;//经纬度
            int lon = 0;//经纬度
            int rowNum=0;//行号
            int columnNum=0;//列号
            for (row = rows; row <rows + rowSpan; row++)
            {
                lan = Convert.ToInt32(row);
                for (column = columns; column < columns + columnSpan; column++)
                {
                    lon = Convert.ToInt32(column);
                    for (smallRow = row; smallRow <= row + 1; smallRow += 0.01m)
                    {
                        rowNum++;
                        for (smallColumn = column; smallColumn <=column + 1; smallColumn += 0.01m)
                        {
                            columnNum++;
                            framString += rowNum.ToString() + "," + columnNum.ToString() + "," + smallColumn.ToString() + "," + smallRow.ToString()+"\r\n";
                        }
                        columnNum = 0;
                    }
                    System.IO.File.WriteAllText(@"G:\RZPU\20141118fishnet\test\" + lan.ToString() + "-" + lon.ToString() + ".csv", framString);
                    framString = "Row," + "Colum," + "framX," + "framY\r\n";
                    rowNum = 0;
                    
                }
                column = columns;
            }
            row = 0;
        }
目录
相关文章
|
2月前
|
存储 数据库
如何在数据库中存储小数:FLOAT、DECIMAL还是BIGINT?
【8月更文挑战第7天】在数据库中存储小数时,需谨慎选择数据类型:FLOAT、DECIMAL 或 BIGINT。FLOAT 存储空间小,适于非关键性小数如温度;但精度有限,可能产生误差。DECIMAL 能精确表示小数,适合货币金额等需要高度准确性的场景,不过占用空间较大。BIGINT 用于整数,若存储小数需额外转换处理。根据精度需求及应用场景选择合适类型至关重要。
|
3月前
|
存储 SQL 数据库
MySQL设计规约问题之为何推荐用DECIMAL代替FLOAT和DOUBLE来存储精确浮点数
MySQL设计规约问题之为何推荐用DECIMAL代替FLOAT和DOUBLE来存储精确浮点数
|
存储 关系型数据库 MySQL
【必看】MySQL中float、double、decimal三个浮点数据类型的区别与总结!
你还不知道MySQL中float、double、decimal三个浮点类型的区别吗?快来看看吧!
454 0
【必看】MySQL中float、double、decimal三个浮点数据类型的区别与总结!
C#基础②——数据类型(decimal和float、double的区别)
double和float都是存小数的,为什么还要分两个,一个不就行了,那它们两个有哪些区别?
|
关系型数据库 MySQL
MySQL中float、double、decimal的区别
MySQL中float、double、decimal的区别
125 0
|
存储 关系型数据库 MySQL
MySQL如何选择float, double, decimal
MySQL如何选择float, double, decimal
293 0