Summary: Learn an easy method to express a percentage in Windows PowerShell.
How can I use Windows PowerShell to express a two-decimal place percentage? For example, I have multiple
calculations in a Windows PowerShell script, and I am tired of always dividing two numbers, multiplying
by a hundred, and trimming the results to two decimal places.
Use the special “P” format specifier as an overload to the ToString method, for example:
PS C:\> (5/21).tostring("P")
23.81 %