-(NSString *)convertCurrency:(NSString *)textFieldString{
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle: NSNumberFormatterNoStyle];
[numberFormatter setGroupingSize:3];
[numberFormatter setGroupingSeparator:@","];
[numberFormatter setUsesGroupingSeparator:YES];
[numberFormatter setMaximumIntegerDigits:20];
number= [NSNumber numberWithInt:[textFieldString intValue]];
NSString *numberString = [NSString stringWithFormat:@"$%@",[numberFormatter stringForObjectValue:number]];
return numberString;
}
When I send the textfield string value is send 10000000000 only return the $2,147,483,647 but I want only $10,000,000,000. how to solve this issue.
Use a long long
. That's assuming $9,223,372,036,854,775,807 is enough.
NSNumber* number = [NSNumber numberWithLongLong:[textFieldString longLongValue]];
NSString* numberString = [numberFormatter stringFromNumber:number];
BTW you could have just used
[numberFormatter setCurrencySymbol:@"$"];
instead of -stringWithFormat:
to add the dollar sign.