大额数字做单位处理

项目中用到 做下记录

#pragma mark - 判断字符串是否为整型

- (BOOL)isPureInt:(NSString *)string{



    NSScanner* scan = [NSScanner scannerWithString:string];



    int val;



    return [scan scanInt:&val] && [scan isAtEnd];



}

#pragma mark - 把大长串的数字做单位处理

- (NSString *)changeAsset:(NSString *)amountStr

{

    if (amountStr && ![amountStr isEqualToString:@""])

    {

        NSInteger num = [amountStr integerValue];

      if (num >= 1000000000000)

        {

            NSString *str = [NSString stringWithFormat:@"%ld",num/1000000000000];



            return [NSString stringWithFormat:@"%@万亿",str];

        } else if (num >= 100000000)

        {

            NSString *str = [NSString stringWithFormat:@"%ld",num/100000000];



            return [NSString stringWithFormat:@"%@亿",str];

        } else if (num >= 10000000)

        {

            NSString *str = [NSString stringWithFormat:@"%ld",num/10000000];



            return [NSString stringWithFormat:@"%@千万",str];

        }else if (num >= 10000)

        {

            NSString *str = [NSString stringWithFormat:@"%ld",num/10000];



            return [NSString stringWithFormat:@"%@万",str];

        }

    }

    return amountStr;

}

 

posted on 2018-04-25 14:50  Aggie1024  阅读(230)  评论(0编辑  收藏  举报

导航