Name

real

Allowed coercions

String
list with one item
integer (if there is no fractional part)
number (a synonym)

Syntax

set theNumber to 25.6 as real

Description

A real is a positive or negative number that can include a decimal point, such as -512.5 or 3.14159265359 (the value of the pi predefined variable is a real value type). Use real when you want a variable to store a very high number. The largest positive value that a real number can reach with AppleScript 1.4.3 on OS 9 is 1.797693E+308. This very large number, however, can safely be exceeded with real data types under AppleScript 1.5.5/1.6 (Mac OS 9.1 and OS X).

Examples

The second line of this example raises an error in AppleScript Version 1.4.3 and Script Editor: “The result of a numeric operation was too large”:

set theVar to 1.797693E+308

set theVar to theVar + 1

At any rate, this is a giant number. To use scientific notation, follow the real or floating-point number with the letter “e” (upper- or lowercase) along with an integer like 20 (e.g., 2.0e20 or 2.0e+20; the “+” is optional, any “-” sign is not). If the integer is a positive n,then the number is equal to real number * 10 n; if n is negative then the number is equal to real number * 10 -n. AppleScript converts to scientific notation the real numbers that are greater than or equal to 10,000.0 when the script is compiled. My machine also converts to scientific notation numbers that are less than or equal to 0.001, but the AppleScript Language Guide for AppleScript ...

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.