Is 100 less than 30?

Hello!

Could someone please explain why Applescript thinks the number 100 is less than the number 30 and how to fix it?

set TestVar1 to "100"
set TestVar2 to "30"

if TestVar1 is less than TestVar2 then
	return "TestVar1 is less than TestVar2"
end if

48

It's because you're setting the variables to strings/text instead of numbers. If you remove the quotes from the numbers, it works as you expect:

set TestVar1 to 100
set TestVar2 to 30

if TestVar1 is less than TestVar2 then
	return "TestVar1 is less than TestVar2"
else
	return "TestVar1 is more than TestVar2"
end if

16%20AM

2 Likes

Hmm, thanks @gglick :slight_smile:

1 Like

@kreal, to add to this, the comparison you originally asked AppleScript to make—being a comparison between two strings—was telling you, not whether the number 100 is less than 30, but whether "100" comes before "30" alphabetically, which it does.

3 Likes