# How to use \ref command in the test block of \ifnum?

Is there a way to use \ref{} inside the test part of \ifnum. The following example runs into an error.

\documentclass{article}

\begin{document}

\begin{table}
\caption{ex}
\label{tab:ex}
\end{table}

\def\a{\ref{tab:ex}}
\ifnum\a>0 y\else n\fi

\end{document}


You can use the command \getrefnumber from the package refcount and define \a as

\def\a{\getrefnumber{tab:ex}}


At this point change your MWE to

\documentclass{article}
\usepackage{refcount}

\begin{document}

\begin{table}
\caption{ex}
\label{tab:ex}
\end{table}

\def\a{\getrefnumber{tab:ex}}
\ifnum\a>0 y\else n\fi

\end{document}


and you will get what you want.