对于这个问题,也只有金融行业会使用到,代码如下((float)(round(i*1000.0)/1000))
1000 代表保留到三位小数,这样我们可以过滤掉0.05000008这样的异常数据,倒是程序出现错误,
在看一段循环计算代码,经过下面这样计算才算正确的使用,不再有失真的数据了,
for (float i = 0.0f ; ((float)(round(i*1000.0)/1000))<= (((int)stopLossingIndex)*(float)(roundf(priceStep*1000.0)/1000)); i+=(float)(roundf(priceStep*1000.0)/1000)) { i = (float)(round(i*1000)/1000); if (i!=0.0f){ NSLog(@"i=%f",i);// NSString * forstr = [NSString stringWithFormat:@"%.2f",i]; [tmpStopLossing addObject:[NSString stringWithFormat:@"%g",i]]; NSLog(@"%@",tmpStopLossing); } }
联系客服