I want to check whether a number \a
(read from a file) is smaller than zero using ifthenelse
:
\ifthenelse{\a<5}{smaller}{not smaller}
This works fine when a is in the format -1
. In the file commas (,
) are used as decimal separators, so \ifthenelse
fails.
Any ideas on how to compare such a number of format -1,23
?
PS: I know siunitx
could probably do it, but it seems to conflict with csvsimple
, so it is not an option.
Best Answer
A decimal number can always be input either with the comma or the period, when TeX's length tests are concerned.
On the other hand, the standard test for
\ifthenelse
compares integer numbers. So we need to do differently:will do, because
\a
will expand to the decimal number and adding the unit point to it will give a legitimate length to be compared with0pt
.One is not forced to use
0pt
: any length is good. So if the test must compare if the given number is less than1.23
,will do. This, of course, will compare correctly numbers with a short decimal part (TeX compares correctly up to the fourth decimal digit, the fifth may not be recognized because of the internal binary arithmetic with truncation).
Either commas or periods for delimiting the decimal part can be used safely.