Reputation: 3889
I am playing around with lisp's format function, but I have hit a snag because although I can get it to write the list of numbers aligned nicely, I can't seem to get it to zero pad it:
(defun inc (a) (+ 1 a))
(dotimes (i 10)
(format t "~3@:D ~:*~R~%" (inc i)))
This produces the following output:
+1: one
+2: two
+3: three
+4: four
+5: five
+6: six
+7: seven
+8: eight
+9: nine
+10: ten
Does anybody know how to get it to be zero-padded?
Upvotes: 7
Views: 3215
Reputation: 17062
Example lifted from the PCL chapter on FORMAT:
(format nil "~12d" 1000000) ==> " 1000000"
(format nil "~12,'0d" 1000000) ==> "000001000000"
Upvotes: 12