4

1000000この String:を次の形式に変換したいのです10,00,000が、次のような出力が得られます :1,000,000これは間違っています。が必要10,00,000です。

私のコード:

NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
         inputnumber = newString;
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencySymbol:@""];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:2];
[formatter setUsesGroupingSeparator:YES];
[formatter setCurrencyGroupingSeparator:@","];
// [formatter setCurrencyDecimalSeparator:@"."];
[formatter setGroupingSeparator:@","];
NSNumber *num = [NSNumber numberWithDouble:[inputnumber doubleValue]];
inputnumber = [formatter stringFromNumber:num];
4

2 に答える 2

3

Swiftの場合、これを確認してください:

 let initalValue:NSString = "1000000"
    let currencyFormatter = NSNumberFormatter()
    currencyFormatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle
    currencyFormatter.locale = NSLocale (localeIdentifier: "en_IN")
    let formattedValue = currencyFormatter.stringFromNumber(initalValue.doubleValue)
    print(formattedValue)
于 2016-08-19T07:26:16.523 に答える