Flash CS4 ActionScript 3.0 Tutorial
How to Round a Number Up 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. In this example we introduce two variables that are rounded up using using the ceil() method. For more information on rounding up and basic rounding see topics, Rounding Down and Basic Rounding.
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.ceil(rnd01);
trace("Using Ceiling, 2.35 becomes " + rnd01);
trace("Using Ceiling, 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 up to the next integer value, which is three. The following line does the same thing for the second variable.
The trace statements display the new rounded values in the Output panel along with some descriptive text.