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.
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}
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}
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
:
\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}
figures
and places
, e.g. \num[...]{12.12}
.
0.1234
as 0.123
, while 0.12
should be printed as it is without adding an additional zero?
\newcommand*{\MyNum}[1]{\pgfmathprintnumber[precision=3]{#1}}
.
Commented
Nov 4, 2019 at 23:26