4

I would like to keep the trailing zeros when the data, used for internal calculations with l3fp, are printed. For example:

\documentclass{article}
\usepackage{siunitx}
\usepackage{expl3}
\pagestyle{empty}
\ExplSyntaxOn
\NewDocumentCommand{\calcnumd}{o m}{\num[#1]{\fp_to_decimal:n{#2}}}
% 
\fp_set:Nn \gpcinque {305.0}
\fp_set:Nn \gptre {272.3}
\ExplSyntaxOff 

\begin{document}

\calcnumd{\gpcinque * sin(pi/2)}\,\si{\kilo\gram}

\calcnumd{\gptre}\,\si{\kilo\gram}

\end{document}

will print 272.3 kg and 305 kg instead of 305.0 kg. Is there a way to avoid the trimming of trailing zeros?

4

The FPU does not have a concept of 'significant zeros' in the input: internally everything is converted to a standard form. If you want to force a number of places or significant digits, you'll need to do so at the point of output:

\documentclass{article}
\usepackage{siunitx}
\usepackage{expl3}
\pagestyle{empty}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\fp_set:Nn \gpcinque {305.0}
\fp_set:Nn \gptre {272.3}
\ExplSyntaxOff 

\begin{document}

\SI{\fpeval{\gpcinque * sin(pi/2)}}{\kilo\gram}

\SI[round-mode = places, round-precision = 1, round-integer-to-decimal]
  {\fpeval{\gpcinque * sin(pi/2)}}{\kilo\gram}

\SI[round-mode = figures, round-precision = 4, round-integer-to-decimal]
  {\fpeval{\gpcinque * sin(pi/2)}}{\kilo\gram}

\end{document}

You can set up the rounding approach in the preamble if it is general.

(I've used \SI and the fact that we can do expandable calculations 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.