Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Created April 27, 2018 13:05
Show Gist options
  • Save mlcollard/f713e82e1f8045466bf0d4b0c23b0544 to your computer and use it in GitHub Desktop.
Save mlcollard/f713e82e1f8045466bf0d4b0c23b0544 to your computer and use it in GitHub Desktop.
iOS: Number Localization playground
// Localization of numbers
import Foundation
let nf = NumberFormatter()
nf.numberStyle = .decimal
print(nf.string(from: 1234) ?? "INVALID NUMBER")
nf.locale = Locale(identifier: "es_ES")
// United States
print(nf.string(from: 1234) ?? "INVALID NUMBER")
// Mexico
nf.locale = Locale(identifier: "es_MX")
print(nf.string(from: 1234) ?? "INVALID NUMBER")
nf.locale = Locale(identifier: "es_MX")
nf.currencySymbol
nf.internationalCurrencySymbol
// French (France)
nf.locale = Locale(identifier: "fr_FR")
nf.currencySymbol
nf.internationalCurrencySymbol
// French (Canada)
nf.locale = Locale(identifier: "fr_CA")
nf.currencySymbol
nf.internationalCurrencySymbol
// Chinese
nf.locale = Locale(identifier: "zh")
nf.currencySymbol
nf.internationalCurrencySymbol
nf.currencyDecimalSeparator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment