Created
March 21, 2018 19:27
-
-
Save vialyx/00c791ff234a89c865fbd05deacc8e03 to your computer and use it in GitHub Desktop.
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
let number = NSNumber(value: 1231.90) | |
let numberFormatter = NumberFormatter() | |
guard let formattedNumber = numberFormatter.string(from: number) else { fatalError() } | |
print("Formatted rounded Number: \(formattedNumber)") | |
// Formatted rounded Number: 1232 | |
numberFormatter.numberStyle = .currency | |
guard let formattedCurrency = numberFormatter.string(from: number) else { fatalError() } | |
print("Formatted currency Number: \(formattedCurrency)") | |
// Formatted currency Number: $1,231.90 | |
numberFormatter.numberStyle = .currencyPlural | |
guard let pluralCurrency = numberFormatter.string(from: number) else { fatalError() } | |
print("Formatted pluralCurrency Number: \(pluralCurrency)") | |
// Formatted pluralCurrency Number: 1,231.90 US dollars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment