我试图删除xcode中两位小数位浮点数的前导零。
arrFraction = [[NSMutableArray alloc] init];
for (float fraction = .00; fraction <=.99; fraction+= .01) {
NSString *fractionString = [NSString stringWithFormat:@"%.2f%", fraction];
[arrFraction addObject:fractionString];
}
这导致NSMutableArray的值为0.00
,但0.99
我想要的是.00
到.99
答案 0 :(得分:3)
尝试这样,
NSString *str =@"0000.00013200";
NSRange range = [str rangeOfString:@"^0*" options:NSRegularExpressionSearch];
str= [str stringByReplacingCharactersInRange:range withString:@""];
NSLog(@"%@",str);
O / P: - .00013200