Numberformatter Swift

[Solved] Numberformatter Swift | Swift - Code Explorer | yomemimo.com
Question : numberformatter swift

Answered by : happy-hyena-j4t6squdpbx2

let currencyFormatter = NumberFormatter()
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.numberStyle = .currency
// localize to your grouping and decimal separator
currencyFormatter.locale = Locale.current
// We'll force unwrap with the !, if you've got defined data you may need more error checking
let priceString = currencyFormatter.string(from: 9999.99)!
print(priceString) // Displays $9,999.99 in the US locale

Source : https://supereasyapps.com/blog/2016/2/8/how-to-use-nsnumberformatter-in-swift-to-make-currency-numbers-easy-to-read | Last Update : Tue, 08 Jun 21

Answers related to numberformatter swift

Code Explorer Popular Question For Swift