julia> lpad(12, 4, 0)
"0012"

On Wed, Jul 20, 2016 at 9:05 AM, Tamas Papp <tkp...@gmail.com> wrote:

> Hi,
>
> how can I @sprintf an integer i padded to length l with zeros, where l
> is not a constant? Current workaround is
>
> printpad(i, l) = mapreduce(string, *, reverse(digits(i, 10, l)))
>
> julia> printpad(12, 4)
> "0012"
>
> but I could not figure out how to do this with @sprintf. If my
> understanding of printf syntax is correct, something like
>
> @sprintf("%*d", 4, 12)
>
> should do the trick, but in Julia it is an invalid format string.
>
> Best,
>
> Tamas
>

Reply via email to