10

Consider the following code:

\documentclass{article}

\usepackage{booktabs}
\usepackage[locale = DE]{siunitx}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\DeclareSIUnit\kroner{kr.}

\newcommand*\skyld[1]{
  \calc{((1+\rente)^(#1)*(\rente*\start-\afbetaling)+\afbetaling)/\rente}
}


\begin{document}

\def\start{612600}
\def\afbetaling{68199}
\def\rente{0.02}

\begin{tabular}{
  S[table-format = 2]
  S[table-format = 6.2, round-mode = places, round-precision = 2]
}
 \toprule
  {$n$} & {$X(n)$}       \\
  {---} & {\si{\kroner}} \\
 \midrule
   0 & \skyld{ 0} \\
   1 & \skyld{ 1} \\
   2 & \skyld{ 2} \\
   3 & \skyld{ 3} \\
   4 & \skyld{ 4} \\
   5 & \skyld{ 5} \\
   6 & \skyld{ 6} \\
   7 & \skyld{ 7} \\
   8 & \skyld{ 8} \\
   9 & \skyld{ 9} \\
  10 & \skyld{10} \\
 \bottomrule
\end{tabular}

\end{document}

output

How do I add 00 as decimals to the first two numbers in the second column? (I know that the two numbers are integers but I would like two decimals nonetheless.)

10

You have to use round-integer-to-decimal.

\documentclass{article}

\usepackage{booktabs}
\usepackage[locale = DE]{siunitx}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\DeclareSIUnit\kroner{kr.}

\newcommand*\skyld[1]{
  \calc{((1+\rente)^(#1)*(\rente*\start-\afbetaling)+\afbetaling)/\rente}
}


\begin{document}

\def\start{612600}
\def\afbetaling{68199}
\def\rente{0.02}

\begin{tabular}{
  S[table-format = 2]
  S[table-format = 6.2, round-integer-to-decimal, round-mode = places, round-precision = 2]
}
 \toprule
  {$n$} & {$X(n)$}       \\
  {---} & {\si{\kroner}} \\
 \midrule
   0 & \skyld{ 0} \\
   1 & \skyld{ 1} \\
   2 & \skyld{ 2} \\
   3 & \skyld{ 3} \\
   4 & \skyld{ 4} \\
   5 & \skyld{ 5} \\
   6 & \skyld{ 6} \\
   7 & \skyld{ 7} \\
   8 & \skyld{ 8} \\
   9 & \skyld{ 9} \\
  10 & \skyld{10} \\
 \bottomrule
\end{tabular}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.