Skip to content

Instantly share code, notes, and snippets.

@latompa
Last active August 29, 2015 14:02
Show Gist options
  • Save latompa/4acd839a8a307d6868f5 to your computer and use it in GitHub Desktop.
Save latompa/4acd839a8a307d6868f5 to your computer and use it in GitHub Desktop.
add commas
(defn commas-foul [n]
(->> n
.toString
reverse
(partition-all 3)
(interpose ",")
flatten
reverse
(apply str)))
;; ty thallgren
(defn commas [n]
(-> Locale/US java.text.NumberFormat/getNumberInstance (.format n)))
(commas 1234)
"1,234"
(commas 4123678)
"4,123,678"
(->> 45)
"45"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment