四舍五入的函数,保留小数点后几位数不四舍五入

 

 

用到了math 里的两个函数 round pow

double Myround(double n,int length){

        return round(n*pow(10, length))/pow(10, length);

}

例如想求12312.4455453 后边的三位小数可以这么写 Myround(12312.4455453,3) 结果为

12312.446000

 

不四舍五入的函数

float SubFlooat(float Src,int length){

    return floor(Src*pow(10, length))/pow(10, length);

}

posted @ 2015-12-15 11:23  鲁国将士  阅读(715)  评论(0编辑  收藏  举报