My English is not enough to search the question. So, I have to write here. My integer is 600000000 for ex. I want to convert it like this: 600,000,000. How do I do this?
Asked
Active
Viewed 86 times
1 Answers
0
extension Int {
struct Number {
static let formatter = NSNumberFormatter()
}
var addThousandSeparator:String {
Number.formatter.groupingSeparator = "."
Number.formatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
return Number.formatter.stringFromNumber(self)!
}
}
let myInteger = 600000000
let myIntegerString = myInteger.addThousandSeparator // "600.000.000"

Leo Dabus
- 229,809
- 59
- 489
- 571
-
I add this in view controller.swift, but there was an error: declaration is only valid at file scope. How do i fix it? Thanks! – Batuhan Kök Aug 19 '15 at 22:58
-
Just add this extension at the bottom of your view controller (outside your view controller) – Leo Dabus Aug 19 '15 at 23:00
-
1Thanks for everything! – Batuhan Kök Aug 19 '15 at 23:09
-
@BatuhanKök you are welcome – Leo Dabus Aug 19 '15 at 23:09