Skip to content

Instantly share code, notes, and snippets.

@AsceticMonk
Last active February 3, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsceticMonk/46e69d27e2ca31d3f231 to your computer and use it in GitHub Desktop.
Save AsceticMonk/46e69d27e2ca31d3f231 to your computer and use it in GitHub Desktop.
NSNumberFormatter basics
import Foundation
let formatter = NSNumberFormatter()
formatter.locale = NSLocale.currentLocale()
// Currency
formatter.numberStyle = .CurrencyStyle
formatter.stringFromNumber(49.99)
// Currency in German
formatter.locale = NSLocale(localeIdentifier: "de_DE")
formatter.stringFromNumber(29.99)
// Spell out style in Japanese
formatter.locale = NSLocale(localeIdentifier: "ja_JP")
formatter.numberStyle = .SpellOutStyle
formatter.stringFromNumber(10)
// Ordinal style
formatter.locale = NSLocale.currentLocale()
formatter.numberStyle = .OrdinalStyle
formatter.stringFromNumber(31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment