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;
    }
  • 相关阅读:
    Android教程 -07 Activity的任务栈和启动模式
    ViewPager封装工具类: 轻松实现APP导航或APP中的广告栏
    hdu 5900 区间dp
    状压dp入门
    poj 3280
    hdu 4745 two Rabits
    食了智,过来水一发
    poj 2142 the Balance
    hdu 6188 Duizi and Shunzi
    hdu 6186 CS Course
  • 原文地址:https://www.cnblogs.com/pengjuwang/p/5422458.html
Copyright © 2011-2022 走看看