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

 

 

用到了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);

}

原文地址:https://www.cnblogs.com/luguojiangshi/p/5047614.html