7

How can I bring down the number of decimal points in following code to only 2:

\documentclass{article}
\usepackage{datatool}

\begin{filecontents*}{test2.csv}
  Name, Age, stDev
  Adam, 17.2344, 3.23333
\end{filecontents*}

\DTLloaddb{mydata2}{test2.csv}

\begin{document}

\begin{tabular}{ll}
  \bfseries Name & \bfseries Age%
  \DTLforeach{mydata2}{\Name=Name,\Age=Age,\stDev=stDev}%
    {%
    \\\Name & $\Age\pm\stDev$
    }%
\end{tabular}

\end{document}
2

1 Answer 1

8

datatool already loads fp which provides \FPround{<out>}{<in>}{<num>}, rounding <in> to <num> decimal places and stores it in <out>. datatool mirrors this with \DTLround (and/or \DTLtrunc if you wish to truncate rather than round):

enter image description here

\documentclass{article}
\usepackage{datatool,filecontents}% http://ctan.org/pkg/{datatool,filecontents}
\begin{filecontents*}{test2.csv}
Name, Age, stDev
Adam, 17.2344, 3.23333
Eve, 17.56789, 3.95445
\end{filecontents*}

\DTLloaddb{mydata2}{test2.csv}

\begin{document}

\begin{tabular}{ll}
\bfseries Name & \bfseries Age%
\DTLforeach{mydata2}{\Name=Name,\Age=Age,\stDev=stDev}%
{%
\\ \Name & \DTLround{\Age}{\Age}{2}\DTLround{\stDev}{\stDev}{2}$\Age\pm\stDev$
}%
\end{tabular}

\end{document}

See p 30 (under section 3 Fixed Point Arithmetic) of the datatool user guide.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .