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 Fix Function

Windows PowerShell

Definition: Returns the integer portion of a number.


Friends, are you plagued by decimal points? Would you just as soon strip off those pesky little decimal values and leave yourself with a clean, pure integer value? Then have we got a deal for you. In Windows PowerShell you can remove decimal places by using the System.Math class and the Truncate method. For example, here we assign the value 11.98 to $a, then use Truncate to remove the .98:

$a = 11.98
$a = [math]::truncate($a)

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


Note. Keep in mind that the truncate method simply removes all numbers following the decimal point; it does not round values to the nearest whole number. If you want to do that, use the Round method instead.

Return to the VBScript to Windows PowerShell home page

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