Scripting

# Weekend Scripter: PowerShell Does Scientific Notation

Doctor Scripto

Summary: Microsoft PFE and guest blogger, Clint Huffman, talks about scientific notation and Windows PowerShell.

Microsoft Scripting Guy, Ed Wilson, is here. Today we have another guest blogger from the past—Clint Huffman. The keyboard is yours Clint…

In Performance Monitor, if a number in a field is too large to display, scientific notation is used to represent the number. A value such as 30,064,771,072 (28 GB) is too large for a field to display, so it is represented as 3.0064e+010. This is not an error—it is scientific notation. It indicates that the decimal point must be moved to the right the number of times indicated after the plus (+) symbol. There are 9 digits behind a gigabyte, so the number 2.8637e+010 in the following image appears as a “ball park” figure of 28 GB. But after dividing each thousands group by 1024, the true answer is 26.7 GB.

Math is hard for me, and I avoid it when I can, so I use Windows PowerShell to help me with it. Windows PowerShell can convert values in gigabytes and return the number in bytes or vice-versa. For example, Windows PowerShell can convert 35GB into the full numeric value of 37580963840 in bytes.

It can convert scientific notation into a full numeric value. For example, in the previous image, I typed the value 3.7580e+010 from Perfmon into Windows PowerShell and it returned 37580000000. Knowing what this number is in gigabytes would be nice, so I divided it by 1GB (Windows PowerShell understands KB as kilobytes, MB as megabytes, and so on) to give me the number in gigabytes. In this case, it didn’t quite return an even 35 GB because the actual number was truncated by Perfmon, but it is close enough.

The editor in me has to add this…

Proper technical documentation is to use a space between the number and the unit, such as 10 GB. The reason I specified 35GB earlier is because in order for Windows PowerShell to interpret the number as 35 gigabytes, the space must be removed between number and the unit—35<space>GB will throw an error.

Enjoy!

~Clint

Cool. Thank you, Clint. I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy