Last active
April 2, 2017 17:32
-
-
Save devjangir/a9166881a396f40a57e7eb23e48d7087 to your computer and use it in GitHub Desktop.
Use NSNumberFormatter in Swift to Make Currency Numbers Easy to Read
This file contains hidden or 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
var currencyFormatter = NumberFormatter() | |
currencyFormatter.usesGroupingSeparator = true | |
currencyFormatter.numberStyle = NumberFormatter.Style.currency | |
// localize to your grouping and decimal separator | |
// set locale to Spanish | |
currencyFormatter.locale = Locale(identifier: "eu_ES") | |
var priceString = currencyFormatter.string(from: 12.50) | |
print(priceString) //output : ("12,50 €") | |
// set locale to US | |
currencyFormatter.locale = Locale(identifier: "en_US") | |
priceString = currencyFormatter.string(from: 12.50) | |
print(priceString) //output : ("$12.50") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment