PowerTip: Format Decimal Numbers in PowerShell

Doctor Scripto

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("#.#")



Discussion is closed.

Feedback usabilla icon