NSString格式的数值比大小

分类! 分类!分类! 如下:

+(BOOL)max:(NSString *)maxStr bStr:(NSString *)bStr{
    NSNumberFormatter *numFormat = [[NSNumberFormatter alloc] init];
    [numFormat setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber *a = [numFormat numberFromString:maxStr];
    NSNumber *b = [numFormat numberFromString:bStr];
    if ([a compare:b] == NSOrderedDescending) {//a大
        return YES;
    }else{
        return NO;
    }
}
+(BOOL)min:(NSString *)minStr bStr:(NSString *)bStr{
    NSNumberFormatter *numFormat = [[NSNumberFormatter alloc] init];
    [numFormat setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber *a = [numFormat numberFromString:minStr];
    NSNumber *b = [numFormat numberFromString:bStr];
    if ([a compare:b] == NSOrderedAscending) {//a小
        return YES;
    }else{
        return NO;
    }
}
+(BOOL)deng:(NSString *)aStr bStr:(NSString *)bStr{
    NSNumberFormatter *numFormat = [[NSNumberFormatter alloc] init];
    [numFormat setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber *a = [numFormat numberFromString:aStr];
    NSNumber *b = [numFormat numberFromString:bStr];
    if ([a compare:b] == NSOrderedSame) {//相等
        return YES;
     }else{
        return NO;
    }
}

你可能感兴趣的:(NSString格式的数值比大小)