Last active
August 29, 2015 14:02
-
-
Save latompa/4acd839a8a307d6868f5 to your computer and use it in GitHub Desktop.
add commas
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
(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