zoukankan      html  css  js  c++  java
  • 金额数字千位分隔符

    NSLog(@"The  end  string:%@",[selfseparatedDigitStringWithStr:@"105000"]);

    2013-05-15 17:19:26.470 ghfghfgh[7837:f803] The begin string:105000

    2013-05-15 17:19:26.471 ghfghfgh[7837:f803] The  end  string:105,000

     

    - (NSString *)separatedDigitStringWithStr:(NSString *)digitString

    {

        NSLog(@"The begin string:%@",digitString);

        NSMutableString *processString = [[NSMutableString alloc]initWithString:digitString];

        

        // 1

        int location = processString.length - 3;

        NSMutableArray *processArray = [NSMutableArrayarray];

        while (location >= 0) {

            NSString *temp = [processString substringWithRange:NSMakeRange(location, 3)];

            

            [processArray addObject:temp];

            if (location < 3 && location > 0)

            {

                NSString *t = [processString substringWithRange:NSMakeRange(0, location)];

                [processArray addObject:t];

            }

            location -= 3;

        }

    //    NSLog(@"processArray = %@",processArray);

        

        // 2

        NSMutableArray *resultsArray = [NSMutableArrayarray];

        int k = 0;

        for (NSString *str in processArray)

        {

            k++;

            NSMutableString *tmp = [[NSMutableStringalloc]initWithString:str];

            if (str.length > 2 && k < processArray.count )

            {

                [tmp insertString:@"," atIndex:0];

                [resultsArray addObject:tmp];

            } else {

                [resultsArray addObject:tmp];

            }

        }

    //    NSLog(@"resultsArray = %@",resultsArray);

        

        // 3

        NSMutableString *resultString = [NSMutableStringstring];

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

        {

            NSString *tmp = [resultsArray objectAtIndex:i];

            [resultString appendString:tmp];

        }

    //    NSLog(@"resultStr = %@",resultString);

        return resultString;

    }

     

     

    祝您愉快开心 ^_^

  • 相关阅读:
    第二个冲刺
    实验四主存空间的分配和回收
    Sprint总结
    Sprint回顾
    Scrum项目5.0
    hibernate jpa 注解 @Temporal(TemporalType.DATE) 格式化时间日期,页面直接得到格式化类型的值
    获得HttpServletResponse及其他对象
    UUID.randomUUID()方法介绍
    psp个人软件过程需求文档
    电子产品自动搜索比价系统设计与实现 项目愿景与范围
  • 原文地址:https://www.cnblogs.com/tianglin/p/3080235.html
Copyright © 2011-2022 走看看