@Round (JavaScript)

Rounds a number.

Defined in

@Functions (JavaScript)

Syntax

@Round(value:double) : double

@Round(value:double, factor:double) : double

Parameter Description
value The number to round.
factor The rounding factor. Defaults to 1.
Return value Description
double The rounded number.

Usage

The default rounding factor (1) rounds the number to an integer. Rounding factors that are powers of 10 provide more or less precision on a decimal basis. For example, if the number to be rounded is 654.321, a rounding factor of 0.001 yields 654.321, 0.01 yields 654.32, 0.1 yields 654.3, 1 yields 654, 10 yields 650, and 100 yields 700.

The parameter and return value can be arrays. The operation acts on the corresponding elements.

Examples

This example shows the effects of rounding several numbers.
function p(stuff) {
	print("<<<" + stuff + ">>>");
}

var pi = Math.PI;

p("Round 25.1 = " + @Round(25.1)); // 25
p("Round 25.5 = " + @Round(25.5)); //26
p("Pi rounded to 0.001 = " + @Round(pi, 0.001)); // 3.142
p("Round 255 to 100 = " + @Round(255, 100)); // 300