始终在NSString返回函数中返回null

时间:2014-10-27 16:13:44

标签: objective-c

我有以下代码,我想将小数赔率转换为小数赔率。但是,函数findNearestWholeInteger始终返回null

- (NSString *)displayOddWithFormat:(NSString *)decimalOdd {

   if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FractionalOdds"] == YES) {
       float oddsF = decimalOdd.floatValue;
       oddsF = oddsF - 1.0f;
       return [self findNearestWholeInteger:oddsF andInitial:oddsF andBottom:1];
   } else {
       return odd;
   }
}

- (NSString *)findNearestWholeInteger:(float)odds andInitial:(float)initial andBottom:(float)bottom {

   NSNumber *numberValue = [NSNumber numberWithFloat:odds];
   NSString *floatString = [numberValue stringValue];
   NSArray *floatStringComps = [floatString componentsSeparatedByString:@"."];

   if (floatStringComps.count == 1) {
       return [NSString stringWithFormat:@"%.f/%.f", odds, bottom];
   } else {
       bottom += 1;
       odds += initial;
       [self findNearestWholeInteger:odds andInitial:initial andBottom:bottom];
       return nil;
   }
}

我需要调整代码的任何想法?提前谢谢!

1 个答案:

答案 0 :(得分:1)

你不想要:

return [self findNearestWholeInteger:odds andInitial:initial andBottom:bottom];
//return nil;

(不是我真的明白这个方法在做什么)。