考虑以下代码:
\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}
如何将00
第二列的前两个数字添加为小数?(我知道这两个数字是整数,但我仍然想要两个小数。)
答案1
你必须使用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}