Use + for addition and for subtraction Use * for multiplication and / for straightforward division Use div for integral division (ignoring the remainder) Use mod for modulus (returning the remainder) Use ^ for exponentiation

Using Barcode creation for Java Control to generate, create bar code image in Java applications.

You can use these operators with either integer numbers or real numbers The type of result depends on the numbers you use For example, if you multiply two integers, you get an integer; but if you multiply an integer by a real number, or a real number by another real number, you get a real number If necessary, you can coerce the result of a calculation to another data type, as discussed next

Using Barcode printer for BIRT Control to generate, create GTIN - 13 image in BIRT applications.

You can easily coerce a number to the other type real number to integer number, or vice versa or to a list or a string To coerce a real number to an integer number in effect, rounding it to the nearest number use as integer For example, 15 as integer returns 2 To coerce an integer number to a real number, use as real AppleScript adds a decimal point and a 0 to the end of the integer number to create the real number For example, 100 as real returns 1000 To coerce an integer number or real number to a string, use as string The string contains the same number as the integer number or real number used For example, 254 as string returns "254"; 255693 as string returns "255693" To coerce an integer number or real number to a list, use as list The result is a singleitem list For example, 189 as list returns the list {189}

AppleScript doesn t let you coerce a boolean value directly to a real value, but there s nothing to stop you from coercing the boolean value to an integer value and then coercing the result to a real value (for example, myBool as integer as real) You ll end up with 10 for a true value and 00 for a false value

string If you have a string that contains a number, you can coerce it to either an integer number or a real number Unless you know that the string contains no fractional part, or you want the result to be an integer number, coercing the string to a real number is usually the safer choice

If you try to coerce a string that contains non-numeric data to a number, AppleScript returns an error

Working with Dates

In your scripts, you ll often need to work with dates, doing everything from returning the current date and time to calculating the number of days or weeks between two dates In this section, you ll come to grips with the powerful set of tools that AppleScript provides for working with dates

Understanding How AppleScript Handles Dates

To work with dates, AppleScript uses the date object The date object is a floatingpoint number with the integer portion representing the date and the fractional portion representing the time within the day

NOTE

The date object puts the Pope firmly above Caesar, using the Gregorian calendar and ignoring the Julian calendar

Treating dates as numbers enables AppleScript (and computers in general) to calculate them easily But AppleScript lets you return any of the components of the date the year, the month, the hour, and so on simply enough

5:

Working with Text, Numbers, and Dates

The date object returns the date in a standard format such as this:

date "Thursday, April 1, 2010 6:14:47 AM"

What you ll normally want to do is get at one or more of the separate parts of the date To do so, use the properties of the date object Table 5-5 explains these properties As you can see in the table, the properties return three types of data: text strings, integer numbers, and weird things (weekday and month) The text strings are great for when you need to insert a date as text (for example, in a document) or display it in a dialog box For example, the following statement returns the day and date from a date object:

date string of date "1 December 2010"

When you compile a script, AppleScript changes a date entered like this into its standard format, including the time, which it sets to midnight if you haven t specified any other time Here s what the compiled statement looks like: