January 28th, 2015

PowerTip: Format Decimal Numbers in PowerShell

Doctor Scripto
Scripter

Summary: Learn how to display a specific number of decimal points in Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to display only one decimal place on a number that currently has two?

Hey, Scripting Guy! Answer Use a custom number format string with the ToString method from the number, for example:

PS C:\> (1.11).tostring("#.#")

1.1

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