Birju Birju - 3 months ago 14
Objective-C Question

How to add dot(.) after every 3 digit?

I have number like 2000000 and i want this number in 2.000.000 while displaying.I tried to use number formatter which is provided by iOS sdk

NSNumberFormatterDecimalStyle
but it adds comma(,).

Thanks in advance.

Answer

You can use the groupingSeparator property of the NSNumberFormatter for that.

Objective-C

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.usesGroupingSeparator = YES;
formatter.groupingSeparator = @".";
NSNumber *number = @(2000000);
NSString *string = [formatter stringFromNumber:number];

Swift 2.2

let formatter = NSNumberFormatter()
formatter.usesGroupingSeparator = true
formatter.groupingSeparator = "."
let number = 2000000
let string = formatter.stringFromNumber(number)