Is there a simple way to format currency into string in iOS?

前端 未结 7 1093

I need a way to format the price from NSNumber into a string like this: \"USD 0.99\", not \"$ 0.99\".

My game uses custom fonts, and they could not have the symbols

7条回答
  •  抹茶落季
    2020-12-23 15:57

    Nice example I found here http://bendodson.com/weblog/2014/12/10/skproduct-localized-price-in-swift/

    import StoreKit
    
    extension SKProduct {
    
        @objc func localizedPrice() -> String {
            let formatter = NSNumberFormatter()
            formatter.numberStyle = .CurrencyStyle
            formatter.locale = self.priceLocale
            return formatter.stringFromNumber(self.price)!
        }
    }
    

提交回复
热议问题