话不多说直接上代码:
-(NSString *)digitUppercase:(NSString *)numstr{
double numberals=[numstr doubleValue];
NSArray *numberchar = @[@"零",@"壹",@"贰",@"叁",@"肆",@"伍",@"陆",@"柒",@"捌",@"玖"];
NSArray *inunitchar = @[@"",@"拾",@"佰",@"仟"];
NSArray *unitname = @[@"",@"万",@"亿",@"万亿"];
//金额乘以100转换成字符串(去除圆角分数值)
NSString *valstr=[NSString stringWithFormat:@"%.2f",numberals];
NSString *prefix;
NSString *suffix;
if (valstr.length<=2) {
prefix=@"零元";
if (valstr.length==0) {
suffix=@"零角零分";
}
else if (valstr.length==1)
{
suffix=[NSString stringWithFormat:@"%@分",[numberchar objectAtIndex:[valstr intValue]]];
}
else
{
NSString *head=[valstr substringToIndex:1];
NSString *foot=[valstr substringFromIndex:1];
suffix = [NSString stringWithFormat:@"%@角%@分",[numberchar objectAtIndex:[head intValue]],[numbercharobjectAtIndex:[foot intValue]]];
}
}
else
{
prefix=@"";
suffix=@"";
NSInteger flag = valstr.length - 2;
NSString *head=[valstr substringToIndex:flag - 1];
NSString *foot=[valstr substringFromIndex:flag];
if (head.length>13) {
return@"数值太大(最大支持13位整数),无法处理";
}
//处理整数部分
NSMutableArray *ch=[[NSMutableArray alloc]init];
for (int i = 0;
i < head.length;
i++) {
NSString * str=[NSString stringWithFormat:@"%x",[head characterAtIndex:i]-'0'];
[ch addObject:str];
}
int zeronum=0;
for (int i=0;
i