April 17th, 2016

PowerTip: Use PowerShell to display a percentage that has two decimal places

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to display a percentage as a two place number.

Hey, Scripting Guy! Question How can I use Windows PowerShell to display a number as a percentage that has two decimal places?

Hey, Scripting Guy! Answer Use the -f format specifier, and specify a pattern as “{0:p2}”. On the other side of the -f format specifier, perform your percentage calculation. Here is an example:

PS C:\> “{0:p2}” -f (1/10)

10.00 %

The Doctor

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback