Today we’re going to take a quick look at a potential “gotcha” that can occur when performing numeric comparisons. Jason DeLooze and I discussed the general behavior back in 2011 (Space Is The Place), but this time around I want to focus on one particular set of circumstances where the problem can arise.
At first glance this may appear to apply to beginner-level developers only, but the problem is nuanced, and I have occasionally seen it crop up in solutions written by experienced developers as well as those created by newbies.
Specifically, when comparing two variables, for example…
ExitLoopIf [ $counter >= $rows ]
…FileMaker must determine whether to do a text comparison or a number comparison, and under certain circumstances, contrary to developer expectations, may perform the comparison in “text space” rather than in “number space”.
Of course we can explicitly ensure that all comparisons take place in “number space” like so…
ExitLoopIf [ GetAsNumber ( $counter ) >= GetAsNumber ( $rows ) ]
…but let’s dig a little deeper to see the circumstances under which GetAsNumber is actually necessary. Continue reading “When 2 is greater than 10”