Converting VBScript's Sgn Function

Definition: Returns an integer indicating the sign of a number.

Sgn

Quick: is that a negative number or a positive number? An easy way to verify that in Windows PowerShell is to use the System.Math class and the Sign method. For example, this command uses the Sign method to determine the sign of -453:

$a = [math]::sign(-453)

When you run this command and then echo back the value of $a you should get the following:

-1

If you check the sign of a positive number (e.g., 453) you should get back something like this (actually, you should get back something exactly like this):

1

Return to the VBScript to Windows PowerShell home page