January 26th, 2015

PowerTip: Round Number Up or Down with PowerShell

Doctor Scripto
Scripter

Summary: Easily use Windows PowerShell to round a number up or down.  

Hey, Scripting Guy! Question I want only a whole number returned, so I want the number rounded up or down as appropriate.
           How can I do this with Windows PowerShell?

Hey, Scripting Guy! Answer Cast the number as an integer, and Windows PowerShell will round the number up or down
           as appropriate, for example:

PS C:\> [int]22.4

22

PS C:\> [int]22.5

22

PS C:\> [int]22.6

23

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.