I want to write a number 1234 in the form 1 234.
I tried

```
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
The number $ 1234 $ is written in the form $ 1\,234 $;

The number $ 123456789 $ is written in the form $ 123\,456\,789$.
\end{document}

```

How can I make it automatically?
[![enter image description here](https://i.stack.imgur.com/dtZcn.png)](https://i.stack.imgur.com/dtZcn.png)