Export (0) Print
Expand All
Expand Minimize

Converting VBScript's Int Function


Windows PowerShell


Definition: Returns the integer portion of a number.

Int

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:



11

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
Show:
© 2014 Microsoft