Name
Sign Function
Class
System.Math
Syntax
Sign(value)-
value Use: Required
Data Type: Any numeric type, including Decimal
A numeric expression
Return Value
Integer
Description
Determines the sign of a number
Rules at a Glance
The return value of the Sign function is
determined by the sign of value, as
follows:
|
If number is |
|
|---|---|
|
Positive |
1 |
|
Zero |
0 |
|
Negative |
-1 |
Programming Tips and Gotchas
Signis useful in cases in which the sign of a quantity defines the sign of an expression. For example:lngResult = lngQty * Sgn(lngValue)
This is a Shared member, so it can be used without creating any objects.
If you are using the
Signfunction to evaluate a result toFalse(0) orTrue(any nonzero value), you could use theCBoolfunction instead.A major use for
Signis to determine the sign of an expression.
VB .NET/VB 6 Differences
The name of this function has changed. In VB 6, it is named
Sgn. In VB .NET, it is
named Sign and is a member of the Math class of
the System namespace.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access