zoukankan      html  css  js  c++  java
  • 大额数字做单位处理

    项目中用到 做下记录

    #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;
    
    }
  • 相关阅读:
    【8-21】java学习笔记03
    【每天一点点】
    【8-20】java学习笔记02
    【8-19】java学习笔记01
    【8-18】JS学习01
    【8-17】HTML测试
    Selenium之WebDriverWait
    Selenium之XPATH定位方法
    Fiddler用法
    微服务架构系统的测试
  • 原文地址:https://www.cnblogs.com/aggie/p/8944667.html
Copyright © 2011-2022 走看看