[plt-scheme] padding numbers

From: Noel Welsh (noelwelsh at gmail.com)
Date: Thu Oct 16 10:08:47 EDT 2008

On Thu, Oct 16, 2008 at 1:33 AM, David Vanderson
<david.vanderson at gmail.com> wrote:
> The other day I wanted to convert an rgb triplet (say 0, 255, 0) into a hex
> representation padded with zeros (#00ff00).  I expected to be able to do
> something like (format "~02x~02x~02x" r g b), analogous to printf in C.
...

> #lang scheme
> (require srfi/13)
> (apply string-append (map (lambda (e)
>                              (string-pad (format "~x" e) 2 #\0))
>                          '(0 255 0)))

I would use number->string instead of format, but otherwise this is
how I would do it.

N.


Posted on the users mailing list.