Monday, 27 May 2013

siunitx carry error when rounding? \num{89.80} renders as 810

siunitx carry error when rounding? \num{89.80} renders as 810

I've found what I'm afraid is either a bug or a supremely foolish error on my part: whenever I ask siunitx to render \num{89.80}, rounding by figures, it renders it as "810.". Likewise, \num{898.0} comes out as "8100.". After a bit of poking around, it appears that this happens whenever rounding a number with more than two digits in such a way that the largest place changes (see other examples below), as if the "9" in "89" is rounded to "10" and then the "8" is incremented to "9" and these are just concatenated. I've included a minimal example below. I'm running pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) and the version of siunitx included in that TeXLive distribution.
\documentclass{article}
\usepackage{siunitx}

\sisetup{round-mode=figures}   
\begin{document}

% these all render very strangely
\num{89.80}                      % 810.
\num[round-precision=3]{89.99}   % 810.0
\num{898.0}                      % 8100.
\num{19.8}                       % 110.
\num{99.8}                       % 910.
\num{9999}                       % 91 000

% these are totally fine
\num{9.98}
\num[round-mode=off]{89.80}
\num[round-mode=places]{89.80}

\end{document}

No comments:

Post a Comment