This is a follow up question to Set all numbers greater than "X" bold.
How can I make it work for decimal numbers?
Or if I have a mix of integer numbers and decimal numbers?
Indeed, if I try the same solution for decimal numbers, it does not work:
\documentclass{article}
\usepackage{array}
\newcommand{\setmaxnum}[1]{%
\gdef\maxnum{#1}%
}
\newcommand{\numtest}[1]{%
\ifnum#1 > \maxnum
$\mathbf{#1}$%
\else
$#1$%
\fi%
}
\begin{document}
\setmaxnum{0.5}
\begin{tabular}{r}
\numtest{0.29}\\
\numtest{0.50}\\
\numtest{0.72}\\
\end{tabular}
\end{document}
\ifnum
tests against integers, it does not understand decimals. You can circumvent this by using\ifdim
and addpt
to the decimal number. See tex.stackexchange.com/q/135492\newcommand{\setmaxnum}[1]{% \gdef\maxnum{#1pt}% } \newcommand{\numtest}[1]{% \ifdim#1pt > \maxnum $\mathbf{#1}$% \else $#1$% \fi% }