# pgfplotstable: Two columns into one with numeric data, but can't round

Question: Relates to the question posed here. I have made one column from two, but I would like to round the numbers off from a precision of 4 to 2. How do I do that?

Here is the MWE:

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}
var & mean & sd \\
x & 95.265 & 11.4801 \\
y & 85.7 & 18.95 \\
z & 15 & 5.01 \\
}\means

\pgfplotstabletypeset[
columns/var/.style={string type},
columns/mean/.style={fixed zerofill,precision=2},
columns/sd/.style={fixed zerofill,precision=2},
columns/mixed/.style={string type,column type=l,column name={Mean (SD)}},
columns={var, mixed},
create on use/mixed/.style={
create col/assign/.code={%
\edef\entry{\thisrow{mean} (\thisrow{sd})}%
\pgfkeyslet{/pgfplots/table/create col/next content}\entry
}
}
]\means\
\end{document}


The column "Mean (SD)" in the output is in the raw data format, even though I had specified the precision in the columns of "mean" and "sd". How do I get it to round off appropriately with zerofill?

-

In your code, you're setting the number printing options for the two output columns mean and sd, but you're not actually printing them (you're only printing the columns var and mixed). Within the mixed column, you're not passing the numbers through the number formatting routine, but inserting them directly from the source table. Replacing \thisrow{mean} with \noexpand\pgfmathprintnumber[fixed zerofill, precision=2]{\thisrow{mean}} and \thisrow{sd} with \noexpand\pgfmathprintnumber[fixed zerofill, precision=2]{\thisrow{sd}} will lead to the desired result:

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}
var & mean & sd \\
x & 95.265 & 11.4801 \\
y & 85.7 & 18.95 \\
z & 15 & 5.01 \\
}\means

\pgfplotstabletypeset[
columns/var/.style={string type},
columns/mixed/.style={string type,column type=l,column name={Mean (SD)}},
columns={var, mixed},
create on use/mixed/.style={
create col/assign/.code={%
\edef\entry{\noexpand\pgfmathprintnumber[fixed zerofill, precision=2]{\thisrow{mean}} (\noexpand\pgfmathprintnumber[fixed zerofill, precision=2]{\thisrow{sd}})}%
\pgfkeyslet{/pgfplots/table/create col/next content}\entry
}
}
]\means\
\end{document}

-
Awesome, thanks so much! I was getting frustrated with that. – Luke Oct 30 '12 at 19:58