Skip to content

Math Functions

Abs

Description

Returns the absolute value of a number.

Syntax

Abs( number )

Arguments

  • Number
    • Any valid numeric expression. If number contains Null, Null is returned; if it is an uninitialized variable, zero is returned.

Example

' Credit notes arrive with negative values; post them as
' positive.
Abs(%LineTotal)   ' -350.00 returns 350

Atn

Description

Returns the arctangent of a number.

Syntax

Atn( number )

Arguments

  • number
    • A numeric expression.

Example

' Atn returns radians. Multiply by 4 for pi.
Atn(1) * 4   ' Returns 3.14159265358979

Cos

Description

Returns the cosine of an angle.

Syntax

Cos( number )

Arguments

  • number
    • A numeric expression.

Example

Cos(0)   ' Returns 1

Exp

Description

Returns 'e' raised to the 'n'th power, where e = 2.71828183.

Syntax

Exp( number )

Arguments

  • number
    • The power to raise 'e' to.

Example

' e raised to the given power -- the inverse of Log.
Exp(1)   ' Returns 2.71828182845905

Fix

Description

Returns the integer portion of a number.

Syntax

Fix( expression )

Arguments

  • expression
    • A numeric expression whose integer portion is returned.
    • If the expression is negative, the Fix function will return the first negative number that is greater than or equal to the expression.

Example

' Fix truncates toward zero, so it does NOT round.
Fix(8.9)    ' Returns 8
Fix(-8.9)   ' Returns -8   (Int would return -9)

Int

Description

Returns the integer portion of a number.

Syntax

Int( expression )

Arguments

  • expression
    • A numeric expression whose integer portion is returned. If the expression is negative, the Int function will return the first negative number that is less than or equal to the expression.

Example

' Int rounds down, which for a negative is away from
' zero.
Int(8.9)    ' Returns 8
Int(-8.9)   ' Returns -9   (Fix would return -8)

Log

Description

Returns the logarithm of a number to a specified base.

Syntax

Log( number, base )

Arguments

  • number
    • A numeric value that must be greater than 0.
  • base
    • Optional. This is the base to use to calculate the logarithm of a number. If this parameter is omitted, the Log function will use a base of 10.

Example

' Natural logarithm -- the inverse of Exp.
Log(2.71828182845905)   ' Returns 1

Rnd

Description

Returns a random number. The Rnd function returns a value less than 1 but greater than or equal to 0.

Syntax

Rnd[(number)]

Arguments

  • number
    • Optional and can be any valid numeric expression.
If number is Rnd generates
Less than zero The same number every time, using number as the seed.
Greater than zero The next random number in the sequence.
Equal to zero The most recently generated number.
Not supplied The next random number in the sequence.

Example

' Rnd returns the same sequence on every run unless
' Randomize is called first, which is a feature when you
' want repeatable test data and a bug when you do not.
Randomize
Int(Rnd * 100) + 1   ' Returns a whole number from 1 to 100

Round

Description

Returns a number rounded to a specified number of digits.

Syntax

Round( number, digits )

Arguments

  • number
    • The number to round.
  • digits
    • The number of digits to round the number to.

Example

' VBScript uses banker's rounding: exact halves go to
' the nearest EVEN number, so 2.5 rounds down and 3.5
' rounds up. This surprises people reconciling totals
' against an ERP that rounds half away from zero.
Round(%UnitPrice * %Qty, 2)   ' 35.00 x 10 returns 350
Round(2.5)                    ' Returns 2
Round(3.5)                    ' Returns 4

Sgn

Description

Returns the sign of a number (represented as an integer).

Syntax

Sgn ( number )

Arguments

  • number
    • The number to return the sign for.
    • If number is greater than zero, the Sgn function will return 1.
    • If number is equal to zero, the Sgn function will return 0.
    • If number is less than zero, the Sng function will return -1.

Example

' -1, 0 or 1 -- useful for branching on the sign of a
' value.
Sgn(%LineTotal)   ' 350.00 returns 1; -350.00 returns -1; 0 returns 0

Sin

Description

Returns the sine of an angle.

Syntax

Sin( number )

Arguments

  • number
    • A numeric value.

Example

Sin(0)   ' Returns 0

Sqr

Description

Returns the square root of a number.

Syntax

Sqr(number)

Arguments

  • number
    • Any valid numeric expression greater than or equal to 0.

Example

Sqr(16)   ' Returns 4

Tan

Description

Returns the tangent of an angle.

Syntax

Tan( number )

Arguments

  • number
    • A numeric value.

Example

Tan(0)   ' Returns 0