Math functions

  • Updated

You can use arithmetic math functions in NetScript in Optimizely Analytics.

Basic operations

This section lists the basic math operations you can perform using NetScript.

number + number

Returns the sum of the inputs.

Function:

number + number

Data type: number

Example:

5 + 7

Result:

12

number - number

Returns the difference between the inputs.

Function:

number - number

Data type: number

Example:

13-10

Result:

3

number * number

Returns the product of the inputs.

Function:

number * number

Data type: number

Example:

7 * 8

Result:

56

number / number

Returns the division of the inputs.

Function:

number / number

Data type: number

Example:

84 / 4

Result:

21

number ^ number

Returns number1 raised to the power of number2.

Function:

number ^ number

Data type: number

Example:

2 ^ 9

Result:

512

Advanced operations

This section lists the advanced math operations you can perform using NetScript.

abs(number)

Returns the absolute value of a numeric expression.

Function:

abs(number)

Data type: number

Example:

abs(-2)

Result:

2

floor(number)

Rounds the number down to the nearest integer.

Function:

floor(number)

Data type: number

Example:

floor(17.36)

Result:

17

round(number[, N])

Rounds the number to the given precision (N), which is 0 by default. Precision value can be positive or negative and indicates the number of decimal places displayed in the rounded number.

Function:

round(number[, <N>])

Data type: number

Example:

round(23.45)
round(23.45, 0)
round(23.45, 1)
round(23.45, -1)

Result:

23
23
23.5
20

truncate(number[, N])

Rounds the number down to the given precision (N), which is 0 by default.

Function:

truncate(number[, <N>])

Data type: number

Example:

truncate(23.45)
truncate(23.45, 0)
truncate(23.45, 1)
truncate(23.45, -1)

Result:

23
23
23.4
20

sqrt(number)

Returns the square root (full-precision decimal) of the input.

Function:

sqrt(number)

Data type: number

Example:

sqrt(64)

Result:

8

least(number(, number)*)

Returns whichever number has the smallest value.

Function:

least(number(, number)*)

Data type: number

Example:

least(7(, 23)*)

Result:

7

greatest(number(, number)*)

Returns whichever number has the largest value.

Function:

greatest(number(, number)*)

Data type: number

Example:

greatest(7(, 23)*)

Result:

23