Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to get a sequence from "01" to "10". I tried

ToString@PaddedForm[#, 1, NumberPadding -> "0"] & /@ Range@10

(*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "010"}*)

But this returns "010" instead of "10". What am I doing wrong?

And yes, I know I can do

StringTake[ToString[PaddedForm[#, 1, NumberPadding -> "0"]], -2] & /@ Range@10

(*{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"}*)

But this feels like a hack.

share|improve this question
    
I would it like so StringJoin@(ToString /@ PadLeft[IntegerDigits[#], 2]) & /@ Range@10? –  swish Apr 18 '13 at 15:09

1 Answer 1

up vote 5 down vote accepted

This may be what you're looking for.

IntegerString[#, 10, 2] & /@ Range[10]
{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"}
share|improve this answer
1  
+1 Yes, love it. But why is PaddedForm not working? –  Ajasja Apr 18 '13 at 18:12
    
I believe that PaddedForm adds padding to the left/right regardless of what is in the middle –  David Carraher Apr 19 '13 at 1:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.