2

我正在尝试删除 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

4

1 回答 1

4

试试这样

    NSString *str =@"0000.00013200";
    NSRange range = [str rangeOfString:@"^0*" options:NSRegularExpressionSearch];
    str= [str stringByReplacingCharactersInRange:range withString:@""];
    NSLog(@"%@",str);

运单:-.00013200

于 2013-09-23T05:49:39.140 回答