A minimal working sample should be give first:

```
\documentclass{article}
\newcounter{mynumber}
\makeatletter 
\AtEndDocument{%
    \immediate\write\@auxout{%
        \string\setcounter{mynumber}{\number\value{mynumber}}%
    }%
}
\makeatother
\AtBeginDocument{%
    \stepcounter{mynumber}
}

\begin{document}
the version number is \themynumber.
\end{document}

```

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).**