Name

integer

Allowed coercions

list with one item
string
real

Syntax

set myInt to 12 as integer

Description

An integer value type is a positive or negative number that does not have a decimal part. You can use number as a synonym for integer, but the class of the variable remains integer, as in:

set aNum to 30 as number

If you get the class property of aNum, it will be integer.

If you need a very high number, such as for a variable that will hold the U.S. national debt, you will have to use a real data type. An integer has a range of-536870911 to +536870911. If you’re going to work with very high numbers, particularly if the script will increase the value of those numbers, then you should use a real value type to hold the value.

Examples

Here are some examples of numbers that AppleScript will store as integers, as well as numbers that AppleScript will end up storing as reals because they are too big or have a fractional part:

integer class

set bigInt to 500000000

integer class

set bigInt to -500000000

The variable bigInt is stored in a real data type because of the size of the number:

set bigInt to 600000000

The variable bigInt is converted to the real class because it has a fractional part:

set bigInt to 6.1

AppleScript automatically sets a data type for a variable depending on the size of the number or whether it has a decimal point. In the following code, the number starts out as an integer, has a number with a decimal point added to it, then is converted to a real value type to accommodate ...

Get AppleScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.