2012-08-09 33 views
0

我創造的貨幣轉換爲Word格式的功能,但我的問題是,當把textfeild值我需要印度格式一個十萬,但它給我十萬所以,任何解決辦法。如何在iphone中將單詞拼寫轉換爲貨幣?

NSString *str1 = txtAmount.text; 
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
    [formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 

    NSString *localeStr = [appDel.countryCodeDict valueForKey:appDel.selectedCountry]; 


    if ([appDel.selectedCountry isEqualToString:@"France"]) { 
     localeStr = @"fr"; 
    } 
    if ([appDel.selectedCountry isEqualToString:@"Germany"]) { 
     localeStr = @"de"; 
    } 


    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:localeStr]; 
    [formatter setLocale:usLocale]; 

    [formatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; 

    [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 


    NSArray *valueArr=[str1 componentsSeparatedByString:@"."]; 


    [formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 

    NSString *firstStr = [valueArr objectAtIndex:0]; 
    NSString *seconfStr = [valueArr lastObject];   

    if (valueArr.count==2 && ![seconfStr isEqualToString:@""]) { 
     double firstAmt = [firstStr doubleValue]; 
     NSString *convertStr = [formatter stringFromNumber:[NSNumber numberWithDouble:firstAmt]]; 

     double secondAmt = [seconfStr doubleValue]; 
     NSString *convertStr1 = [formatter stringFromNumber:[NSNumber numberWithDouble:secondAmt]]; 

     NSString *finalStr = [convertStr stringByAppendingFormat:@" %@ %@ %@",appDel.firstCurrencystr,convertStr1,appDel.secondCurrencystr]; 
     NSLog(@"%@",finalStr); 
     NSString *firstCapChar = [[finalStr substringToIndex:1] capitalizedString]; 

     tempStr = [finalStr stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar]; 

    }else{ 

     double firstAmt = [firstStr doubleValue]; 
     NSString *convertStr = [formatter stringFromNumber:[NSNumber numberWithDouble:firstAmt]]; 
     convertStr = [convertStr stringByAppendingFormat:@" %@",appDel.firstCurrencystr]; 
     NSString *firstCapChar = [[convertStr substringToIndex:1] capitalizedString]; 
     tempStr = [convertStr stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar]; 

    } 

    appDel.lblAmountView.lblAmount.text = tempStr; 

的任何想法。

+0

你需要分享一些代碼,以確保它是一個可操作的問題。 – bryanmac 2012-08-09 05:03:30

+0

我仍然不明白這個問題。 – 2012-08-09 05:12:29

+0

@MichaelDautermann當我把txtAmount.text = 100000然後它將字格式轉換成十萬格式,但我需要一個十萬(印度格式)。 – Dhaval 2012-08-09 05:18:56

回答

2
at last i convert the hole currency in lakh and crore format of india: 



-(NSString *)stringfromNumberIndia:(NSString *)str_word 
    { 
     NSString *[email protected]""; 

     NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 
     [formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 

     NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"]; 
     [formatter setLocale:usLocale]; 
     [formatter setNumberStyle: NSNumberFormatterSpellOutStyle]; 


     if ([str_word length]>5) { 

      NSString* str_convert = [str_word substringFromIndex:[str_word length]-5]; 
      NSString* str_convert1 = [str_word substringToIndex:[str_word length]-5]; 
      NSLog(@"str :%@",str_convert); 
      NSLog(@"str1 :%@",str_convert1); 
      tempStr = [[self stringfromNumberIndia:str_convert] stringByAppendingString:tempStr]; 
      int l=[str_convert1 length]; 
      for (int i=0; i<l;) { 

       NSRange range; 
       if (l>2 && i == 0) { 
        range=NSMakeRange(l-i-2, 2); 
       } 
       else{ 
        range=NSMakeRange(0, l-i); 
       } 
       NSString *str_first=[str_convert1 substringWithRange:range]; 
       if ([str_first intValue] == 0) { 
        if (i == 0) 
         i+=2; 
        else 
         break; 
        continue; 
       } 
       NSLog(@"str_first:%@",str_first); 
       if (i== 0) { 
        str_first=[formatter stringFromNumber:[NSNumber numberWithDouble:[str_first doubleValue]]]; 
        str_first = [str_first stringByAppendingFormat:@" lakh "]; 
        tempStr = [str_first stringByAppendingString:tempStr]; 
       } 
       else { 
        str_first =[self stringfromNumberIndia:str_first]; 
        str_first = [str_first stringByAppendingFormat:@" crore "]; 
        tempStr = [str_first stringByAppendingString:tempStr]; 
        break; 
       } 
       i+=2; 
      } 
     } 
     else if ([str_word intValue] !=0){ 
      double Amt = [str_word doubleValue]; 
      NSString *convertStr = [formatter stringFromNumber:[NSNumber numberWithDouble:Amt]]; 

      NSString *firstCapChar = [convertStr substringToIndex:1]; 
      tempStr = [convertStr stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar]; 
     } 
     return tempStr; 

    } 

感謝。

2

不要」知道你有什麼編碼,但如果你想貨幣是在印度風格看看這個代碼: -

NSLocale *indiaLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"] autorelease]; 
double currency = 1000000000.00; 
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; 
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; 
[numberFormatter setLocale:indiaLocale]; 

NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithInt:currency]]; 
NSString *str2 = [NSString stringWithFormat:@"Converted:%@",numberAsString]; 

NSLog(@"String:%@",str2); 
+0

問題要求以印度格式拼出來 – 2016-10-26 04:02:49