Specify exact number of digits?

if the output:

Range [1,10]

is: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

how can I get:

{001, 002, 003, 004, 005, 006, 007, 008, 009, 010} ?

with 3, or other, exact number of digits?

tnk’s

one way might be

r = Range[1, 10];
AccountingForm[r, 2, NumberPadding -> {"0", ""}]

9436Untitled.png

It works for numbers 1 or 2 digits, but the reason why I want to get the output with 3-digit is because the output already contains a 3-digit numbers, with your formula the 3-digit numbers become 4-digit …

there is a way to map placeholders, such ###, with my numbers 1, 2 or 3 digits, and replace the empty positions with 0?

If you mean selectively padding the 1 or 2 digit numbers with leading zeroes, then you can rewrite [what Nasser has suggested]-

Range[1, 105] /.x_ /; IntegerLength[x] < 3 ->AccountingForm[x, 2, NumberPadding -> {"0", ""}]

AccountingForm does not return strings, which is what the OP probably wants:

StringPadLeft[ToString[#], 3, "0"] & /@ Range[1, 10]

StringPadLeft (for string) or PadLeft (for lists) can be used to pad to a fixed number of characters/items.

If output with Strings is okay, then you can also write-

IntegerString[#, 10, 3] & /@ Range[1, 100]

That is also very nice solution! You can’t really do anything with AccountingForm except for display, if you want to export something or concatenate with other words/characters you’ll need strings…

Dear @Mutatis Mutandis you do not need to format code as bold font type. There is a proper formatting for code as you can see in many posts on this forum. Please learn about proper posting here: https://wolfr.am/READ-1ST