# Set all numbers greater than "X" bold, for decimal numbers

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}


I get the following output:

• \ifnum tests against integers, it does not understand decimals. You can circumvent this by using \ifdim and add pt to the decimal number. See tex.stackexchange.com/q/135492 Commented Aug 9 at 15:39
• Thanks a lot, by using the following, it worked: \newcommand{\setmaxnum}[1]{% \gdef\maxnum{#1pt}% } \newcommand{\numtest}[1]{% \ifdim#1pt > \maxnum $\mathbf{#1}$% \else $#1$% \fi% } Commented Aug 9 at 15:47

You can't compare decimal numbers with \ifnum, that only compares integers.

\documentclass{article}
\usepackage{array}

\newcommand{\setmaxnum}[1]{%
\gdef\maxnum{#1}%
}

\ExplSyntaxOn

\NewDocumentCommand{\numtest}{m}
{
\fp_compare:nTF { #1 > \maxnum } { $\mathbf{#1}$ } { $#1$ }
}

\ExplSyntaxOff

\begin{document}

\setmaxnum{0.5}
\begin{tabular}{r}
\numtest{0.29}\\
\numtest{0.50}\\
\numtest{0.72}\\
\end{tabular}

\end{document}


• Thanks a lot!! I can see it is a bit different syntax from \ifnum or \ifdim#1pt ...Something new to learn today :-) Commented Aug 9 at 15:50