The pgfmath functions give me unexpected results when used on numbers with leading zeros. Are the output in the example below expected for 0011 and 0021?
\documentclass{article}
\usepackage{tikz}
\newcommand\truncateline[2]{%
#1 & #2 & \pgfmathtruncatemacro{\foo}{#1}\foo \\%
}
\newcommand\roundline[2]{%
#1 & #2 & \pgfmathround{#1}\pgfmathresult \\%
}
\newcommand\intline[2]{%
#1 & #2 & \pgfmathint{#1}\pgfmathresult \\%
}
\begin{document}
\section{pgfmathtruncatemacro}
\begin{tabular}{lll}
Input & Expected & Output \\
\truncateline{0}{0}
\truncateline{1}{1}
\truncateline{01}{1}
\truncateline{001}{1}
\truncateline{0011}{11}
\truncateline{0021}{21}
\end{tabular}
\section{pgfmathround}
\begin{tabular}{lll}
Input & Expected & Output \\
\roundline{0}{0}
\roundline{1}{1}
\roundline{01}{1}
\roundline{001}{1}
\roundline{0011}{11}
\roundline{0021}{21}
\end{tabular}
\section{pgfmathint}
\begin{tabular}{lll}
Input & Expected & Output \\
\intline{0}{0}
\intline{1}{1}
\intline{01}{1}
\intline{001}{1}
\intline{0011}{11}
\intline{0021}{21}
\end{tabular}
\end{document}
.0to the input causes pgf to interpret the numbers in base 10 irrespective of the leading 0.\pgfmathtruncatemacro{\foo}{0021.0}\foogives21as desired. – Martin Heller Apr 17 '12 at 10:33\the\numexpr <number>\relaxwould limit the usefulness of using\pgfmath. This seems to be working for me but just wanted to make sure that there is not some other problem with this. Also, using\pgfmathparse{\removeleadingzeros{31} - \removeleadingzeros{07}}\pgfmathresultyieldsArgument of \removeleadingzeros has an extra }., but works fine if I replaced the07with just7. – Peter Grill Sep 22 '12 at 18:36<number>can only by a validnumexpr, so all advancedpgfmathexpressions are no longer allowed. – Martin Scharrer Sep 23 '12 at 07:44