Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Operators > % modulo operator | |||
expression1 % expression2
Calculates the remainder of expression1 divided by expression2. If either of the expression parameters are non-numeric, the modulo (%) operator attempts to convert them to numbers. The expression can be a number or string that converts to a numeric value.
The sign of the result of modulo operation matches the sign of the dividend (the first number). For example, -4 % 3 and -4 % -3 both evaluate to -1.
Availability: ActionScript 1.0; Flash Player 4 - In Flash 4 files, the <code>%</code> operator is expanded in the SWF file as <code>x - int(x/y) * y</code> and may not be as fast or as accurate in later versions of Flash Player.
expression1 : Number - A number or expression that evaluates to a number.
expression2 : Number - A number or expression that evaluates to a number.
Number - The result of the arithmetic operation.
The following numeric example uses the modulo (%) operator:
trace(12%5); // traces 2 trace(4.3%2.1); // traces 0.0999999999999996 trace(4%4); // traces 0
The first trace returns 2, rather than 12/5 or 2.4, because the modulo (%) operator returns only the remainder. The second trace returns 0.0999999999999996 instead of the expected 0.1 because of the limitations of floating-point accuracy in binary computing.
/ division operator, round (Math.round method)
Version 8
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00001843.html