# How to set the precision in numbers

I include the number as \num{0.12368455}. I need to print '0.1237'.

How to do this...

-

With the the siunitx package you can use the option round-mode=places, round-precision=4 to obtain the desired results.

1. If you only need to control the rounding for a few numbers you use it as an option to \num:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
\num{0.12368455}

\num[round-mode=places,round-precision=4]{0.12368455}
\end{document}

2. If you need to do this for the entire document you can use \sisetup{round-mode=places,round-precision=4} so that this formatting is applied for the entire document:

\documentclass{article}
\usepackage{siunitx}
\sisetup{round-mode=places,round-precision=4}

\begin{document}
\num{0.12368455}
\end{document}

3. Another way of achieving this is to use round-mode=figures, round-precision=4.

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\num[round-mode=figures,round-precision=4]{0.12368455}\par
\num[round-mode=figures,round-precision=4]{0.12}\par
\num[round-mode=places,round-precision=4]{0.12368455}\par
\num[round-mode=places,round-precision=4]{0.12}
\end{document}


## round-mode=figures vs round-mode=places

With [round-mode=figures,round-precision=4] you get 4 significant figures, and with [round-mode=places,round-precision=4] you get 4 decimal places. Here is a comparison:

Similar results can also be achieved using \pgfmathprintnumber:

## Code:

\documentclass{article}
\usepackage{pgf}

\newcommand*{\MyNum}[1]{%
\pgfmathprintnumber[
fixed,
precision=4,
fixed zerofill=true,
]{#1}}%

\begin{document}
\MyNum{0.12368455}\par
\MyNum{0.12}
\end{document}

-
Thanks to Jake and Peter Grill... – sandu Jun 8 '12 at 6:50
@PeterGrill I'd suggest adding another example to the third paragraph to visualize the difference between figures and places, e.g. \num[...]{12.12}. – dgs Jun 9 '12 at 10:07
@dgs: Have added the requested info. If it can be improved in any way, please let me know. – Peter Grill Jun 10 '12 at 7:29
@PeterGrill Nicely done, thanks. – dgs Jun 10 '12 at 14:34