有没有人知道如何将double值格式化为没有千位分隔符的String(在Swift-ios中).
注意:我需要考虑当前的语言环境,因为一些欧洲语言使用逗号(,)作为小数分隔符.例如德语languange写12.50为12,50.
所以如果double值是1250.25
English-uk : 1250.25
German     : 1250,25
Run Code Online (Sandbox Code Playgroud)
如果我使用以下两种方式(英国英国)我得到的值为(1,212.50).但我想将值格式化为String而不使用thousant分隔符.所以在这种情况下1212.50
var testOne = String.localizedStringWithFormat("%.2f", 1212.50)
var testTwo = String(format: "%.2f", locale: NSLocale.currentLocale(), 1212.50)
Run Code Online (Sandbox Code Playgroud)
    您需要在数字上使用NSNumberFormatter并将分组分隔符显式设置为空字符串:
let formatter = NSNumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US")  // locale determines the decimal point (. or ,); English locale has "."
formatter.groupingSeparator = ""  // you will never get thousands separator as output
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
formatter.numberStyle = .DecimalStyle
let result = formatter.stringFromNumber(1233.99)  // you will always get string 1233.99
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1617 次  |  
        
|   最近记录:  |