Skip to content

Instantly share code, notes, and snippets.

@aboedo
Created February 14, 2022 18:19
Show Gist options
  • Save aboedo/cc1fff7275e2eaee476c6728e1a31674 to your computer and use it in GitHub Desktop.
Save aboedo/cc1fff7275e2eaee476c6728e1a31674 to your computer and use it in GitHub Desktop.
import Foundation
let usLocale = Locale(identifier: "en-US")
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = usLocale
formatter.currencyCode = "eur"
let formattedEurosInUS = formatter.string(from: NSNumber(value: 584.5))!
formatter.currencyCode = "usd"
let formattedDollarsInUS = formatter.string(from: NSNumber(value: 584.5))!
print(formattedEurosInUS)
print(formattedDollarsInUS)
let spainLocale = Locale(identifier: "es-ES")
formatter.locale = spainLocale
formatter.currencyCode = "eur"
let formattedEurosInSpain = formatter.string(from: NSNumber(value: 584.5))!
formatter.currencyCode = "usd"
let formattedDollarsInSpain = formatter.string(from: NSNumber(value: 584.5))!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment