删除小数点后面多余的0,比如90.00100可以转换成90.001
//删除小数点后面多余的0
-(NSString *)changeFloat:(NSString *)stringFloat
{
NSInteger length = [stringFloat length];
if ([stringFloat containsString:@"."]) {
for(NSInteger i = length - 1; i >= 0; i--)
{
NSString *subString = [stringFloat substringFromIndex:i];
if(![subString isEqualToString:@"0"])
{
if ([subString isEqualToString:@"."]) {
return [stringFloat substringToIndex:[stringFloat length] - 1];
}else{
return stringFloat;
}
}
else
{
stringFloat = [stringFloat substringToIndex:i];
}
}
}
return 0;
}
网友评论