Forcing string comparisons, or When is "0" not 0?

Devin Asay devin_asay at
Wed Oct 14 16:19:09 EDT 2015

In a simple calculator exercise I’m doing with my class I need to know whether the string in a field is "0" vs. "0.” (The latter can occur when the user enters zero + dot into the calculator display field.) If it’s just “0” the next next number key press should replace the contents of the display field; if it’s “0.” the next number key should be placed *after* the display field. But if the contents of fld “display” is “0.”, all of the following evaluate as TRUE:

   fld “display” = “0.” # as expected
   fld “display" = 0 # makes sense, because right side of comparison is a number
   fld “display” = “0” # seems like this ought to be comparing string to string
   char 1 to 2 of fld “display” is “0” # Really?!
Shouldn’t there be a way to force a string comparison? I know LC tries to be all helpful about casting numerals as numbers, but what if I want to know if it’s the exact string?

I guess I could do this dance:

  if char 1 of fld “display” is “0” and char 2 of fld “display” is NOT “0” then…

It’s seems to complicated for such a simple thing, especially for explaining to novice programmers. Maybe I’m missing something obvious.


Devin Asay
Office of Digital Humanities
Brigham Young University

More information about the use-livecode mailing list