我正在使用fp
LaTeX 添加一些值。我怎样才能用\erg
逗号替换 . (在德国,逗号用作小数点)。
\documentclass{minimal}
\usepackage{fp}
\begin{document}
\FPset\erg{0}
\FPadd\erg{\erg}{23.20}
\FPadd\erg{\erg}{38.46}
\FPadd\erg{\erg}{22.36}
\FPadd\erg{\erg}{22.00}
\FPadd\erg{\erg}{15.00}
\FPclip\erg\erg
The sum is \erg\
\end{document}
答案1
我将使用siunitx
它来进行打印,并使用 LaTeX3 FPU 来进行计算:
\documentclass{article}
\usepackage{siunitx}
\sisetup{locale = DE}
\ExplSyntaxOn
\newcommand*{\fpeval}[1]{\fp_eval:n {#1}}
\newcommand*{\addto}[2]{\fp_set:Nn #1 { #1 + (#2) }}
\ExplSyntaxOff
\begin{document}
\newcommand*{\erg}{0}
\addto{\erg}{23.20}
\addto{\erg}{38.46}
\addto{\erg}{22.36}
\addto{\erg}{22.00}
\addto{\erg}{15.00}
The sum is \num{\fpeval{\erg}}
\end{document}
答案2
\documentclass[preview,border=12pt,varwidth]{standalone}% change this line back to your own document class
\usepackage[nomessages]{fp}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}
\begin{document}
\FPset\erg{0}
\FPadd\erg{\erg}{23.20}
\FPadd\erg{\erg}{38.46}
\FPadd\erg{\erg}{22.36}
\FPadd\erg{\erg}{22.00}
\FPadd\erg{\erg}{15.00}
\FPclip\erg\erg
The sum is \num{\erg}
\end{document}