Reputation: 23
I'm trying to remove the leading zero on a two decimal place float in xcode.
arrFraction = [[NSMutableArray alloc] init];
for (float fraction = .00; fraction <=.99; fraction+= .01) {
NSString *fractionString = [NSString stringWithFormat:@"%.2f%", fraction];
[arrFraction addObject:fractionString];
}
This results in a NSMutableArray with values of 0.00
though 0.99
What I would like is .00
through .99
Upvotes: 2
Views: 1157
Reputation: 8460
try like this,
NSString *str =@"0000.00013200";
NSRange range = [str rangeOfString:@"^0*" options:NSRegularExpressionSearch];
str= [str stringByReplacingCharactersInRange:range withString:@""];
NSLog(@"%@",str);
O/P:-.00013200
Upvotes: 4