1
我使用CurrencyStyle數字格式化程序。它產生像「$ 521.00」的輸出。是否可以在不編寫自定義數字格式化程序的情況下刪除尾隨.XX的簡單方法?快速貨幣式不帶零
我想輸出像「$ 1,521」沒有尾隨零。
var asCurrency: String {
let formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
formatter.locale = NSLocale(localeIdentifier: "en_US")
if let formattedPrice = formatter.stringFromNumber(self) {
return formattedPrice
}