zoukankan      html  css  js  c++  java
  • 添加千分的分隔符

    +(NSString*)strmethodComma:(NSString*)string
    {
     

       NSString *sign = nil;
        if ([string hasPrefix:@"-"]||[string hasPrefix:@"+"]) {
            sign = [string substringToIndex:1];
            string = [string substringFromIndex:1];
        }
        
        NSString *pointLast = [string substringFromIndex:[string length]-3];
        NSString *pointFront = [string substringToIndex:[string length]-3];
        
        int commaNum = ([pointFront length]-1)/3;
        NSMutableArray *arr = [NSMutableArray array];
        for (int i = 0; i < commaNum+1; i++) {
            int index = [pointFront length] - (i+1)*3;
            int leng = 3;
            if(index < 0)
            {
                leng = 3+index;
                index = 0;
                
            }
            NSRange range = {index,leng};
            NSString *stq = [pointFront substringWithRange:range];
            [arr addObject:stq];
        }
        NSMutableArray *arr2 = [NSMutableArray array];
        for (int i = [arr count]-1; i>=0; i--) {
            
            [arr2 addObject:arr[i]];
        }
        NSString *commaString = [[arr2 componentsJoinedByString:@","] stringByAppendingString:pointLast];
        if (sign) {
            commaString = [sign stringByAppendingString:commaString];
        }
        return commaString;

    }
  • 相关阅读:
    Python装饰器的解包装(unwrap)
    《Python cookbook》 “定义一个属性可由用户修改的装饰器” 笔记
    关于Python的函数(Method)与方法(Function)
    判断python对象是否可调用的三种方式及其区别
    tornado返回指定的http code
    Mac下安装pymssql
    iptables
    OpenFlow通信流程解读
    Prometheus的架构及持久化
    ansible总结
  • 原文地址:https://www.cnblogs.com/yuejunjie/p/4826440.html
Copyright © 2011-2022 走看看