此方法结果保留两位小数。
- (NSString *)digitTransformIntoChchr:(NSString *)inputText
{
NSMutableString *moneyStr = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[inputText doubleValue]]];
NSArray *MyScale = @[@"分", @"角", @"元", @"拾", @"佰", @"仟", @"万", @"拾", @"佰", @"仟", @"亿", @"拾", @"佰", @"仟", @"兆", @"拾", @"佰", @"仟" ];
NSArray *MyBase = @[@"零", @"壹", @"贰", @"叁", @"肆", @"伍", @"陆", @"柒", @"捌", @"玖"];
NSMutableString *MStr = [[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];
[MStr appendString:MyBase[MyData]];
if([[moneyStr substringFromIndex:moneyStr.length - i + 1] integerValue] == 0 && i != 1 && i != 2)
{
[MStr appendString:@"元整"];
break;
}
[MStr appendString:MyScale[i - 1]];
}
return MStr;
}