Search
Joe Pruitt - A Software Architect's take on Network Security
You are here: DevCentral > Weblogs

posted on Thursday, January 08, 2009 8:03 AM

PowerShell Welcome to this addition of the PowerShell ABC's where you'll find 26 posts detailing a component of the PowerShell scripting language, one letter at a time.  Today's letter is the letter "N" and for this letter I'm going to discuss one of the core types of objects you'll likely be dealing with: Numbers.

PowerShell supports all of the basic .NET numeric types and performs conversions to and from the different types as needed.  The types, along with the PowerShell type names are in the following table


.NET Full Type Name | PowerShell Short Type Name | Example

System.Int32 [int] 1
System.Int64 [long] 4294967296
System.Double [double] 1.2
System.Decimal [decimal] 1d

Default Type Determiniation

numbers If you don't specify a type for a literal, the system will figure out the best type and way to represent the number. 

Integers (System.Int32) will be used by default and if the literal value is too large to fit into a 32-bit integer, then a long 64-bit integer (System.Int64) will be used.  If it's too large for a 64 bit integer, or if it contains a decimal point, then a double (System.Double) will be used. 

The System.Single type is supported but is typically not used as it provides no advantages over the System.Double type.

There is one condition where you will want to specify the type and that would be for the decimal type (System.Decimal).  This is done by placing a "d" after the number with no whitespace in between.

Multiplier Suffixes

The PowerShell team was kind enough to add some special suffixes for numbers to make managing larger numbers easier.  The following table lists the special powers of two modifiers supported by PowerShell


Multiplier Suffix | Multiplication Factor | Example | Equivalent Value | .NET Type

kb 1024 1kb 1024 System.Int32
1.1kb 1126.4 System.Double
mb 1024*1024 1mb 1048576 System.Int32
1.1mb 1153433.6 System.Double
gb 1024*1024*1024 1gb 1073741824 System.Int32
1.1gb 1181116006.4 System.Double
tb* 1024*1024*1024*1024 1tb 1099511627776 System.Int64
1.1tb 1209462790553.6 System.Double
pb* 1024*1024*1024*1024*1024 1pb 1125899906842624 System.Int64
1.1pb 1.23848989752689E+15 System.Double

*Note, that tb (terabyte) and pb (petabyte) were added in PowerShell v2.

Don't forget the hexidecimals

The last type of number literals are hexidecimals.  Hexidecimal numbers are in base-16 and thus use the 16 distinct symbols [0-9] and [A-F] to represent the values 0-15 respectively.  PowerShell follows the same notation as C, C++, C#, and many other languages in that you prefix the number with the sequence Zero-X ("0x") and allowing the letters A-F (in either case) as extra digits. 0x10 -> 16, 0xF -> 16, and so on.



Feedback

7/20/2010 6:13 PM
Gravatar Mysterious figures.......
uggs online

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 5 and 3 and type the answer here:

Blog Stats

Posts:379
Comments:1067
Stories:1
Trackbacks:301
  

Article Categories

  iRules
  

Image Galleries

  

Joe's bookshelf: read

The Lost Gate
4 of 5 stars
This one started slow but I got really got into it about 1/3 of the way through. If you are an Ender's Game fan, you'll probably like this one as well.

goodreads.com


82,243 Members in 102 Countries and Growing!

Join DevCentral Today!

About DevCentral

DevCentral has been a successful, thriving community for many years. We have always strived to bring you the best technical documentation, discussion forums, blogs, media and much more that we can.

So dive in, get familiar with DevCentral. We hope you like it, we hope it makes your job easier, and lets you get that much more power out of the community. To learn more, make sure to check out the Getting Started section. And if you have any problems, or think something could be easier to use, drop us a line to let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback       or