Skip to main content

Sgn

Returns an integer indicating the sign of a number.

Synopsis

Sgn(number)

Arguments

The number argument can be any valid numeric expression.

Description

The Sgn function has the following return values:

If Number Is Sgn Returns
Greater than zero 1
Equal to zero 0
Less than zero –1

The sign of the number argument determines the return value of the Sgn function. If number is the empty string ("") or a non-numeric value, Sgn returns 0. Sgn resolves multiple sign values; for example, --7 is equivalent to +7, and thus returns 1.

Examples

The following example uses the Sgn function to determine the sign of a number:

Dim MyVar1, MyVar2, MyVar3
MyVar1 = 12: MyVar2 = -2.4: MyVar3 = 0
Println Sgn(MyVar1)    ' Returns 1.
Println Sgn(MyVar2)    ' Returns -1.
Println Sgn(MyVar3)    ' Returns 0.
Println Sgn("")        ' Returns 0.
Println Sgn("a")       ' Returns 0.

See Also

FeedbackOpens in a new tab