Flash CS4 ActionScript 3.0 Tutorial
How to Round a Number Up or Down to a Whole Number with Flash ActionScript
With ActionScript, you can round a number up (ceiling), round a number down (floor) or round up or down depending on the fractional value.
Add a new layer called Actions
Option double-click (PC - Alt double-click) the keyframe in the Actions layer to open the ActionScript panel.
Copy/Paste the following code to the ActionScript panel.
rnd01 = Math.round(rnd01);
trace("Using Rounding, 2.35 becomes " + rnd01);
trace("Using Rounding, 5.75 becomes " + rnd02);
Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The new rounded values display in the Output panel.
Dissecting the Code
The first two lines of the code establish two number variables named rnd01, and rnd02 and sets the initial value for each variable. The next line rounds the first variable down since the fractional value is less than .5. The following line rounds the value up since .75 is larger than .5.
The trace statements display the new rounded values in the Output panel along with some descriptive text.