在iOS中转换失败

时间:2019-05-27 22:17:46

标签: objective-c

出现此错误:

  

隐式转换失去整数精度:'unsigned long'到'int'

针对:

for (int i = abbrev.count - 1; i >= 0; i--) {

下面代码行

-(NSString *)abbreviateNumber:(int)num {
    NSString *abbrevNum;
    float number = (float)num;

    //Prevent numbers smaller than 1000 to return NULL
    if (num >= 1000) {
        NSArray *abbrev = @[@"K", @"M", @"B"];

        for (int i = abbrev.count - 1; i >= 0; i--) {
            // Convert array index to "1000", "1000000", etc
            int size = pow(10,(i+1)*3);

            if(size <= number) {
                // Removed the round and dec to make sure small numbers are included like: 1.1K instead of 1K
                number = number/size;
                NSString *numberString = [self floatToString:number];

                // Add the letter for the abbreviation
                abbrevNum = [NSString stringWithFormat:@"%@%@", numberString, [abbrev objectAtIndex:i]];
            }

尝试修复此错误行。

0 个答案:

没有答案