Name

*

Syntax

10 * 3.14

Return value

An integer if the left-hand operator is an integer and the right-hand operand is either an integer or can be coerced to an integer (for example, 3.0 can be coerced to 3); otherwise a real. Finally, if both operands are integers but the result will exceed the numerical limit of an integer type (536,870,911 to -536,870,911), than the return result is a real.

Description

The multiplication operator is used to multiply two integers, two reals, or an integer and a real. The return result is an integer or a real, depending on the factors explained in the previous paragraph. The lessons that you learned in your early math classes apply to this operator as well; AppleScript will evaluate a multiplication expression before it will evaluate addition or subtraction. For example, the expression 10 + 7 * 5 results in 45, not 85.

You can multiply a number times a string if the string looks like a number. AppleScript first coerces the string to an integer or real (depending on whether the string has a decimal point), and then performs the multiply operation.

Examples

10 + 7 * 5 -- results in 45 not 85; (10 + 7) * 5 results in 85 set aNum to 10 * 3.0 (* aNum is an integer type, because left-hand operand is an integer and right-hand operand can be coerced to an integer *) set aNum to 10.0 * 3.0 -- aNum is a real type set aNum to 30000000 * 20 (* aNum is a real, because the result exceeds the storage capacity of an integer, even though both operands are integers *) ...

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.