June 17th, 2014

PowerTip: Use PowerShell to Round Numbers

Doctor Scripto
Scripter

Summary: Learn how to use Windows PowerShell to round numbers.

Hey, Scripting Guy! Question Is there an easy way to use Windows PowerShell to round numbers up or down in a computation that produces a large amount of numbers after the decimal point?

Hey, Scripting Guy! Answer Use the static Round method from the [math] class:

PS C:> $a = 22/7

PS C:> $a

3.14285714285714

PS C:> [math]::Round($a)

3

PS C:>

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.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Michael .

    How would this be different than: [int]$a