I need to define a Roundup function that is "defined as the smallest number, specified to one decimal place, that is equal to or higher than its input." For example, Round up (4.02) is 4.1; and Round up (4.00) is 4.0.
So far I've come up with this MWE, which nearly does the job :
\documentclass{article}
\usepackage{pgfmath}
\newcommand{\roundup}[1]{%
\pgfmathparse{(ceil(#1*10)/10}%
\pgfmathprintnumberto[precision=1,fixed]{\pgfmathresult}{\roundednumber}
\roundednumber%
}%
\begin{document}
roundup(4.02) = \roundup{4.02} \qquad (should be 4.1)
roundup(4.0) = \roundup{4.0} \qquad (should be 4.0)
roundup(-0.27) = \roundup{-0.27} \qquad (should be -0.2)
\textbf{Problem : }
roundup(-0.2) = \roundup{-0.2}\qquad (should be -0.2)
\textbf{Reason}
\pgfmathparse{ceil(-2)}\pgfmathresult \qquad(this is OK)
\pgfmathparse{ceil(-0.2*10)}\pgfmathresult \qquad(\textbf{this is KO})
\end{document}
However, sometimes it poses problem.
In the end, it boils down to the ceil function, and how pgfmath handles decimal numbers.
How can I right this behavior ?