1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| /** 金额大小写转换
@param money 金额字符串 @return 中文大写金额 */ - (NSString *)digitUppercase:(NSString *)money { NSMutableString *moneyStr = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[money doubleValue]]]; NSArray *MyScale = @[@"分", @"角", @"元", @"拾", @"佰", @"仟", @"万", @"拾", @"佰", @"仟", @"亿", @"拾", @"佰", @"仟", @"兆", @"拾", @"佰", @"仟" ]; NSArray *MyBase = @[@"零", @"壹", @"贰", @"叁", @"肆", @"伍", @"陆", @"柒", @"捌", @"玖"]; 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]; if (MyData == 0) { if (![M hasSuffix:@"零"] && M.length != 0) { [M appendString:@"零"]; } } else { [M appendString:MyBase[MyData]]; if ([[moneyStr substringFromIndex:moneyStr.length-i+1] integerValue] == 0 && i != 1 && i != 2) { [M appendString:@"元"]; break; } [M appendString:MyScale[i-1]]; } } return M; }
|