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

Objective c 在NSString返回函数中始终返回null,objective-c,Objective C,我有下面的代码,我想把十进制赔率转换成分数赔率。但是,函数findNearestWholeInteger始终返回null - (NSString *)displayOddWithFormat:(NSString *)decimalOdd { if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FractionalOdds"] == YES) { float oddsF = decimalOdd.floatValue

我有下面的代码,我想把十进制赔率转换成分数赔率。但是,函数
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;
   }
}
我需要修改代码的地方有什么想法吗?提前谢谢

您不想要:

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

(我并不真正理解该方法在做什么)。

如果您不希望某个方法返回
nil
,请不要使用
returnnil语句