Created
May 22, 2021 21:59
-
-
Save olopsman/ef067b682c30eb56cf4f582f056fed19 to your computer and use it in GitHub Desktop.
Currency formatter for swiftui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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