Created
October 11, 2017 04:16
-
-
Save bagpack/16d218fc464d6f287a3a32d16035b831 to your computer and use it in GitHub Desktop.
ex) 9999 -> "9,999"
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
extension Int { | |
func decimal() -> String { | |
struct Static { // swiftlint:disable:this nesting cache formatter | |
static var formatter: NumberFormatter! = nil | |
} | |
if Static.formatter == nil { | |
let formatter = NumberFormatter() | |
formatter.numberStyle = .decimal | |
formatter.groupingSeparator = "," | |
formatter.groupingSize = 3 | |
Static.formatter = formatter | |
} | |
return Static.formatter.string(from: NSNumber(value: self))! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment