Changes

Jump to: navigation, search

Basic Windows PowerShell 1.0 Types

1,812 bytes added, 14:48, 18 November 2008
New page: == PowerShell Numeric Types == Windows PowerShell 1.0 supports the full range of .Net number types as outlined in the following table: <table border="1" cellpadding="5" cellspacing="0" i...
== PowerShell Numeric Types ==

Windows PowerShell 1.0 supports the full range of .Net number types as outlined in the following table:

<table border="1" cellpadding="5" cellspacing="0" id="E3B" style="border-collapse: collapse; border-color:#cccccc; border-style: solid; border-width: 1px; margin-bottom:20px">
<tr bgcolor="#cccccc" style="color:black" valign="top">
<th>
<p>.Net Type Name</p>
</th>
<th>
<p>Short Type Name</p>
</th>
<th>
<p>Example</p>
</th>
</tr>

<tr>
<td>
System.Int32
</td>
<td>
[int]
</td>
<td>
20
</td>
</tr>

<tr bgcolor="#e9e9e6">
<td>
System.Int64
</td>
<td>
long
</td>
<td>
20000000000
</td>
</tr>

<tr>
<td>
System.Double
</td>
<td>
[double]
</td>
<td>
2.1
</td>
</tr>

<tr bgcolor="#e9e9e6">
<td>
System.Decimal
</td>
<td>
[decimal]
</td>
<td>
2d
</td>
</tr>

<tr>
<td>
System.Byte
</td>
<td>
[byte]
</td>
<td>
2
</td>
</tr>

</table>

When using a number, it is not usually necessary to prefix the value with the type since PowerShell is generally able to ascertain the correct type based on the size and format of the value. If, for example, the value is too high for an ''Int32'' an ''Int64'' may be created. Similarly, if the number contains a fraction then a ''Decimal'' or ''Double'' type will be used.

It is possible to identify the type of a variable by using the ''gettype()'' method of the object. For example:

<pre>
PS C:\Users\Administrator> $myval = 10.432
PS C:\Users\Administrator> $myval.gettype()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
</pre>

As illustrated in the above PowerShell console output, a variable assigned the value 10.432 is stored as type ''Double'' by Windows PowerShell.

Navigation menu