iOS分离数字

- (NSString *)getNumberFromStr:(NSString *)content {
    //处理content,分离数字
    NSScanner *scanner = [NSScanner scannerWithString:content];
    [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    double number;
    [scanner scanDouble:&number];
    // eg: 12.51
    NSString *num = [NSString stringWithFormat:@"%.2f",number];
    return num;
}

你可能感兴趣的:(iOS分离数字)