User Guide
Math.round() 441
Math.round()
Availability
Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using
approximations and might not be as accurate as the non-emulated math functions that Flash
Player 5 supports.
Usage
Math.round(x:Number) : Number
Parameters
x
A number.
Returns
A number; an integer.
Description
Method; rounds the value of the parameter x up or down to the nearest integer and returns
the value. If parameter
x is equidistant from its two nearest integers (that is, the number ends in
.5), the value is rounded up to the next higher integer.
Example
The following example returns a random number between two specified integers.
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
for (var i = 0; i<25; i++) {
trace(randRange(4, 11));
}
See Also
Math.ceil(), Math.floor()