Skip to content

Instantly share code, notes, and snippets.

@mihi-tr
Created August 22, 2014 15:21
Show Gist options
  • Save mihi-tr/28b4d176dba7d33057e6 to your computer and use it in GitHub Desktop.
Save mihi-tr/28b4d176dba7d33057e6 to your computer and use it in GitHub Desktop.
Zero Pad a number in Clojure
(defn zp "Zero Pad numbers - takes a number and the length to pad to as arguments"
[n c]
(loop [s (str n)]
(if (< (.length s) c)
(recur (str "0" s))
s)))
@abogoyavlensky
Copy link

abogoyavlensky commented Apr 4, 2021

(defn zp
  "Zero Pad numbers - takes a number and the length to pad to as arguments"
  [n c]
  (format (str "%0" c "d") n))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment