在swift中,我该怎么做?

时间:2015-08-19 22:41:38

标签: swift numbers integer

我的英语不足以搜索问题。所以,我必须写在这里。我的整数是600000000 ex。我想像这样转换它:600,000,000。我该怎么做?

1 个答案:

答案 0 :(得分: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"