Converting VBScript's CLng Function

Definition: Returns an expression that has been converted to a Variant of subtype Long.


“Long” values are integers in the range -2,147,483,648 to 2,147,483,647. The following two commands show how you can convert a value to the long data type. In command no. 1 we assign a value to the variable $a; in command no. 2 we then convert $a to a long value:

$a = "123456789.45"
$a = [long] $a

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


Note. What happened to the .45 on the end of our original value? Well, remember, long values must be integers. Therefore Windows PowerShell rounds a value to the nearest whole number when converting that value to the long data type.

Return to the VBScript to Windows PowerShell home page