PowerShell offers several options for interacting with numbers and numeric data.
To define a variable that holds numeric data, simply assign it as you would other variables. PowerShell automatically stores your data in a format that is sufficient to accurately hold it.
$myInt
gets the value of 10,
as a (32-bit) integer.
$myDouble
gets the value of
3.14, as a (53-bit, 9 bits of precision) double.
$To explicitly assign a number as a long (64-bit) integer or decimal (96-bit, 96 bits of precision), use the long and decimal suffixes:
$myLong
gets the value of 1,
as a long integer.
$myDecimal
gets the value of
0.999.
PowerShell also supports scientific notation:
$myPi
gets
3.141592653.
The datatypes in PowerShell (integer, long integer, double, and decimal) are built upon the .NET datatypes of the same name.
Since computer administrators rarely get the chance to work with
numbers in even powers of ten, PowerShell offers the numeric constants
of gb
, mb
, and kb
to represent gigabytes, megabytes, and
kilobytes, respectively:
To directly enter a hexadecimal number, use the hexadecimal
prefix 0x
:
$myErrorCode
gets the integer
value 65098.
The PowerShell scripting language does not natively support other number bases, but its support for interaction with the .NET framework enables conversion to and from binary, octal, decimal, and hexadecimal:
$myBinary
gets the integer
value of 2901.
$myOctal
gets the integer
value of 342391.
$myHexString
gets the string
value of “fe4a”
$myBinaryString
gets the
string value of “11000000111001”
See the section “Working with the .NET Framework” to learn more about using PowerShell to interact with the .NET Framework.
18.218.209.8