Question

I want to format the number separated by comma, same as the iphone calculator format , i just use the following code but it shows the Wrong format for example if i enter 100000 it shows 1,00,000 . the correct format is 100,000 Please help

NSNumberFormatter *formatter1 = [[NSNumberFormatter alloc] init];
[formatter1 setNumberStyle:NSNumberFormatterDecimalStyle];
Was it helpful?

Solution

You need to add grouping Size to 3 :

NSNumberFormatter *formatter1 = [NSNumberFormatter new];
[formatter1 setUsesGroupingSeparator: YES];
[formatter1 setGroupingSeparator: @","];
[formatter1 setGroupingSize: 3];

NSString *numberString = [formatter1 stringFromNumber: [NSNumber numberWithInteger: 1000000]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top