数字转繁体汉字(含小数)

- (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];
       NSString *typeStr = MyScale[i - 1];
       if (MyData != 0) {
           [MStr appendString:MyBase[MyData]];

           if([[moneyStr substringFromIndex:moneyStr.length - i + 1] integerValue] == 0 && i != 1 && i != 2)
           {
              [MStr appendString:@"元整"];
              break;
           }
           [MStr appendString:typeStr];
       }else{
           if ([typeStr isEqualToString:@"元"]) {
               [MStr appendString:typeStr];
           }
       }
   }

   return MStr;
}

你可能感兴趣的:(数字转繁体汉字(含小数))