Skip to content

Instantly share code, notes, and snippets.

@olopsman
Created May 22, 2021 21:59
Show Gist options
  • Save olopsman/ef067b682c30eb56cf4f582f056fed19 to your computer and use it in GitHub Desktop.
Save olopsman/ef067b682c30eb56cf4f582f056fed19 to your computer and use it in GitHub Desktop.
Currency formatter for swiftui
struct ContentView: View {
// MARK: Properties
private var amount: Double = 0.00
private var currencyFormatter: NumberFormatter = {
let f = NumberFormatter()
f.numberStyle = .currency
return f
}()
// MARK: Body
var body: some View {
HStack {
Text(currencyFormatter.string(from: NSNumber(value: amount)) ?? "0.00")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment