Is there a format string for zero padding a decimal with the sign in front?
(format nil ? 5) => "+0005"
(format nil ? -5) => "-0005"
The closest I found was
(format nil "~4,'0@d" 5) => "00+5"
(format nil "~4,'0@d" -5) => "00-5"
This is a draft of a custom printer function:
(defun signed-padding (stream data colonp atsignp &optional (padding 0))
(declare (ignore colonp atsignp))
(format stream "~:[+~;-~]~v,'0d" (minusp data) padding (abs data)))
...and an example:
(values
(format nil "~v/signed-padding/" 20 330)
(format nil "~5/signed-padding/" -4))
"+00000000000000000330"
"-00004"
You could probably add more checks and options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With