zoukankan      html  css  js  c++  java
  • OC金额转大写

    -(NSString *)digitUppercaseWithMoney:(NSString *)money
    {
        NSMutableString *moneyStr=[[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[money doubleValue]]];
        NSArray *MyScale=@[@"分", @"角", @"元", @"拾", @"佰", @"仟", @"万", @"拾", @"佰", @"仟", @"亿", @"拾", @"佰", @"仟", @"兆", @"拾", @"佰", @"仟" ];
        NSArray *MyBase=@[@"零", @"壹", @"贰", @"叁", @"肆", @"伍", @"陆", @"柒", @"捌", @"玖"];
    
        NSArray *integerArray = @[@"拾", @"佰", @"仟", @"万", @"拾万", @"佰万", @"仟万", @"亿", @"拾亿", @"佰亿", @"仟亿", @"兆", @"拾兆", @"佰兆", @"仟兆"];
    
    
        NSMutableString * M = [[NSMutableString alloc] init];
        [moneyStr deleteCharactersInRange:NSMakeRange([moneyStr rangeOfString:@"."].location, 1)];
        for(NSInteger i=moneyStr.length;i>0;i--)
        {
            NSInteger MyData=[[moneyStr substringWithRange:NSMakeRange(moneyStr.length-i, 1)] integerValue];
            [M appendString:MyBase[MyData]];
    
            //判断是否是整数金额
            if (i == moneyStr.length) {
                NSInteger l = [[moneyStr substringFromIndex:1] integerValue];
                if (MyData > 0 &&
                    l == 0 ) {
                    NSString *integerString = @"";
                    if (moneyStr.length > 3) {
                        integerString = integerArray[moneyStr.length-4];
                    }
                    [M appendString:[NSString stringWithFormat:@"%@%@",integerString,@"元整"]];
                    break;
                }
            }
    
            if([[moneyStr substringFromIndex:moneyStr.length-i+1] integerValue]==0
               && i != 1
               && i != 2)
            {
                [M appendString:@"元整"];
                break;
            }
            [M appendString:MyScale[i-1]];
        }
        return M;
    }
  • 相关阅读:
    Chapter 7 Integrity(完整性), Views(视图), Security(安全性), and Catalogs(目录)
    Qt计时器
    linux命令:linux文件处理命令
    JSON.stringify()的不常见用法
    flex知识点归纳
    css伪类
    开发资源汇总
    Math.cbrt() Math.sqrt() Math.pow()
    代码开发注意事项和规范
    关于数组数据容易忽略的点
  • 原文地址:https://www.cnblogs.com/pengjuwang/p/5422458.html
Copyright © 2011-2022 走看看