double类型的数据怎样截取
double n=3.254
double m=6.258
我想把任何double类型的数据都截取为只有两位,并且都要进一,不管是否为四舍五入。
这样
n=3.26
m=6.26

解决方案 »

  1.   

    double ceil( double x );
     The ceil function returns a double value representing the smallest integer that is greater than or equal to x. There is no error return.我认为这样:  ceil(n*100)/100;
      

  2.   

    ceil()的返回值好像是整数,这样误差就大了
      

  3.   

    lz看一看,我ceil里边是一个n*100,这样就不怕误差了,小数点后面的两个数肯定能取到的,还有ceil返回值是double类型的,我也测试过了,可以达到你的要求的。
      

  4.   

    非常感谢 biosheep(慢慢在CSDN中成长)