Math

Purpose:

Perform a mathematical calculation.

Category:

Mathematical

Syntax:

Math "formula" decimalPlaces [variable]

formula

A mathematical formula. The formula can include operators and functions like +, -, *, / (see the complete list of supported symbols below). Parentheses and variables may also be used in formulas.

decimalPlaces

The number of decimal places to include in the result. Use 0 (zero) to round the result to the nearest whole number or -1 to have VisualNEO Web automatically determine the optimal number of decimal places

variable

The name of the variable to store the result.

Example:

In the example below, a variable [MonthlyRent] is used to calculate the amount of rent paid per week. [monthlyRent] could be set using the SetVar Action, or associated with a Text Entry object to allow the user to enter a number. The result is stored in the variable [weeklyRent].


SetVar [monthlyRent] 1200

Math "([monthlyRent]*12)/52" 2 [weeklyRent]

-> expected value: 276.92

Supported symbols:

+

Addition Operator eg. 2+3 results 5

-

Subtraction Operator eg. 2-3 results -1

/

Division operator eg 3/2 results 1.5

*

Multiplication Operator eg. 2*3 results 6

Mod

Modulus Operator eg. 3 Mod 2 results 1

(

Opening Parenthesis

)

Closing Parenthesis

Sigma

Summation eg. Sigma(1,100,n) results 5050

Pi

Product eg. Pi(1,10,n) results 3628800

n

Variable for Summation or Product

pi

Math constant pi returns 3.14

e

Math constant e returns 2.71

C

Combination operator eg. 4C2 returns 6

P

Permutation operator eg. 4P2 returns 12

!

factorial operator eg. 4! returns 24

log

logarithmic function with base 10 eg. log 1000 returns 3

ln

natural log function with base e eg. ln 2 returns .3010

pow

power function with two operator pow(2,3) returns 8

^

power operator eg. 2^3 returns 8

root

underroot function root 4 returns 2

sin

Sine function

cos

Cosine function

tan

Tangent function

asin

Inverse Sine funtion

acos

Inverse Cosine funtion

atan

Inverse Tangent funtion

sinh

Hyperbolic Sine funtion

cosh

Hyperbolic Cosine funtion

tanh

Hyperbolic Tangent funtion

asinh

Inverse Hyperbolic Sine funtion

acosh

Inverse Hyperbolic Cosine funtion

atanh

Inverse Hyperbolic Tangent funtion


Remark 1

Math action accept complex formulas as its first parameter: 

Example:        Math "pow(9, 1/2)" 0 [number] 
               
               -> expected value: 3


Remark 2

Javascript has a lot of built-in mathematical functions that can be used. See Section Advanced for 

information about the communication between NeoScript and Javascript.


  Example:

BeginJS

  alert("Minimum: " + Math.min(-2, -3, -1)); //-> -3

EndJS



Random

Purpose:

Generate a random number between 0 (inclusive) and a maximum value (inclusive).

Category:

Mathematical

Syntax:

Random maxVal [variable]

maxVal

The maximum possible value for the generated number. The number returned will be somewhere between 0 (zero) and maximum value (inclusive).

variable

The name of the variable to store the random number.

Example:

Random 3 [number]

-> expected value: 0, 1, 2 or 3



RandomEx

Purpose:

Generate a random number between a minimum (inclusive) and a maximum value (inclusive).

Category:

Mathematical

Syntax:

Random minVal maxVal [variable]

minVal

The minimum possible value for the generated number. 

maxVal

The maximum possible value for the generated number.

variable

The name of the variable to store the random number.

Example:

RandomEx 1 3 [number]

-> expected value: 1, 2 or 3


ToNumber

Purpose:

Convert a string variable to a number.

Category:

Mathematical

Syntax:

ToNumber [string var] [result var]

[string var]

Variable with text content.

[result var]

Variable to store the numeric result

Example:

SetVar [myvar] "3 monkeys"
ToNumber [myvar] [number]

-> expected [number] value: 3