[Tex/LaTex] How to left-pad an integer with zeroes to make it many digits


A minimal working sample should be give first:


the version number is \themynumber.

Compiling it with XeLateX, we will get the version number such as 1. Then my QUESTION is

  • how to make 1 become 0001 and 23 become 0023 and so on (i.e., four-digit numbers)? Note that I want the format like 0001 but not 0 001 (i e., no unit, no space).

Best Answer

with package siunitx:

the version number is \num[minimum-integer-digits = 4]{\themynumber}.

and for Sans Serif

\textsf{\num[detect-family,minimum-integer-digits = 4]{\themynumber}}.