Taking Alan's example and modifying it, you can use the various calculation functions in datatool
to do something like
\documentclass{article}
\usepackage{booktabs,datatool}
\usepackage[margin=1in]{geometry}
\DTLloaddb{stores}{stores.csv}
\newcommand*\calcpercent[1]{%
\DTLdiv{\tmp}{#1}{\subtotal}%
\DTLmul{\tmp}{\tmp}{100}%
\DTLround{\tmp}{\tmp}{1}%
\tmp\,\%
}
\def\total{0}
\DTLforeach{stores}{\subtotal=Sub Total}{\DTLadd{\total}{\total}{\subtotal}}
\begin{document}
\begin{tabular}{llllllll}
Header row
\DTLforeach{stores}{%
\store=Store,%
\one=Product 1,%
\two=Product 2,%
\three=Product 3,%
\four=Product 4,%
\five=Product 5,%
\subtotal=Sub Total%
}{%
\\
\store & \one & \two & \three & \four & \five & \subtotal
&
\DTLdiv{\tmp}{\subtotal}{\total}%
\DTLmul{\tmp}{\tmp}{100}%
\DTLround{\tmp}{\tmp}{1}%
\tmp\,\%
\\
& \calcpercent{\one}
& \calcpercent{\two}
& \calcpercent{\three}
& \calcpercent{\four}
& \calcpercent{\five}
}\\
\end{tabular}
\end{document}
I've not done any formatting here, but the general idea should be clear. (I'd also note that LaTeX is a typesetting system: if you need to do lots of processing, consider a script tool such as Perl, Python or Lua to pre-process the input .csv into a modified one containing the results.)
You can use pgfplotstable
for this. If you load the array
package, you can set the option dec sep align
for pgfplotstabletypeset
to get the alignment at the decimal point. Padding the numbers with zeros can be accomplished by setting fixed zerofill
, the number of decimals can be set using precision
, either for all columns or for individual columns by using display column/<index>/precision=<digits>
.

\documentclass{article}
\usepackage{filecontents} % For the example data
\usepackage{pgfplotstable}
\usepackage{array} % For aligining at decimal point
\begin{filecontents}{testdata.csv}
theta, x, y
30.0, 0.0, 0.0
60.0, 1.9098, 5.8779
90.0, 6.9098, 9.5106
120.0, 13.09, 9.5106
150.0, 18.09, 5.8779
180.0, 20.0, 0.0
\end{filecontents}
\begin{document}
\pgfplotstableread[col sep=comma]{testdata.csv}{\table}
\pgfplotstabletypeset[
dec sep align, % Align at decimal point
fixed zerofill, % Fill numbers with zeros
precision=4, % Set number of decimals
display columns/0/.style={precision=1}, % Change for first column (column 0)
] {\table}
\end{document}
Alternatively, you can use pgfplotstable
and the siunitx
package to align the columns. I've used it here in conjunction with booktabs and properly formatted column headers:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{filecontents}{testdata.csv}
theta, x, y
30.0, 0.0, 0.0
60.0, 1.9098, 5.8779
90.0, 6.9098, 9.5106
120.0, 13.09, 9.5106
150.0, 18.09, 5.8779
180.0, 20.0, 0.0
\end{filecontents}
\begin{document}
\pgfplotstableread[col sep=comma]{testdata.csv}{\table}
\pgfplotstabletypeset[
dec sep align=S, % Use the siunitx `S` column type for aligning at decimal point
fixed zerofill, % Fill numbers with zeros
precision=4, % Set number of decimals
display columns/0/.style={
precision=1, % Change for first column (column index 0)
column name=$\theta_{2,i}$
},
display columns/1/.style={column name=$X$},
display columns/2/.style={column name=$Y$},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
] {\table}
\end{document}
Best Answer
May I suggest you to use pgfplotstable? It works great with CSV files and gives you a lot of control. Here's a nice example: