0

通貨を Word 形式に変換する関数を作成しますが、私の問題は、テキスト フィールドの値を100000に設定すると、インド形式で 1000 万必要ですが、10 万が得られるので、そのための解決策です。

 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;

それについての考え。

4

2 に答える 2

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);
于 2012-08-09T05:49:55.690 に答える
2
at last i convert the hole currency in lakh and crore format of india:



-(NSString *)stringfromNumberIndia:(NSString *)str_word
    {
        NSString *tempStr=@"";

        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;

    }

ありがとう。

于 2012-08-13T14:07:10.930 に答える