Compare floating point numbers in Latex

Abhi picture Abhi · Apr 20, 2010 · Viewed 8.9k times · Source

I am trying to use \ifthenelse to do a floating point comparison. This is the pgf/tikz code, which works if \y is integer only, but not otherwise:

\foreach \y in {3,3.5,...,6} {
    ifthenelse{\y<3}{
        ...
    }{
        ...
    }
}

Answer

Alexey Malistov picture Alexey Malistov · Apr 20, 2010

You can not use floating variables. Use dimens instead of. For example

\newdimen \y 
\y = 3.2pt
\ifdim \y < 3.45pt ... \else ... \fi