Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Round Function

Windows PowerShell

Definition: Returns a number rounded to a specified number of decimal places.


When working with system administration scripts (and performing chores like returning free disk space on a drive) you’ll often get back numbers similar to this: 45.987654321. More often than not you don’t really need all those decimal places; instead, you’d just as soon round the value up (or down).

OK; in Windows PowerShell all you have to do is use the System.Math class and the Round method. This command rounds the number 45.987654321 to two decimal places (notice the value 2 passed as the second parameter to the method). The resulting value is then stored in the variable $a:

$a = [math]::round(45.987654321, 2)

When you run this command and then echo back the value of $a you should get the following:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft