Convert Scientific Notation to Decimal with PowerShell

Have you ever run into a problem where the results from a PowerShell command are returned in scientific notation? I’ve recently been working with performance counters in PowerShell and I’ve run into several scenarios where this occurs such as the one shown in the following example.

In addition to returning the results in the previous example, they were also stored in a variable so the same value could be used throughout this blog article.

Windows PowerShell version 5.1 is used in the examples shown in this blog article. The performance counter cmdlets do not exist in PowerShell Core.

Only the value for the performance counter itself is returned in the following example.

To convert the scientific notation value shown in the previous example to decimal, remove “E-05” from end of it and move the decimal point left the number of places specified by the notation. That would be five decimal places in this scenario. If the notation were positive, it would need to be moved to the right that many decimal places.

While you could write a complicated function to perform the conversion, the simplest way is to cast it as a decimal.

A second way of casting it as a decimal is shown in the following example.

As referenced by Wikipedia, Scientific Notation is a way of expressing numbers that are too big or too small to be conveniently written in decimal form”.

µ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: