Export (0) Print
Expand All
Expand Minimize

Converting VBScript's CInt Function


Windows PowerShell


Definition: Returns an expression that has been converted to a Variant of subtype Integer.

CInt

Need to convert a value to the integer data type? No problem: not only will Windows PowerShell make the conversion for you, but it will also round the value off to the nearest whole number. (Some languages convert a value to an integer simply by stripping off the decimal point.) The following two commands assign a string value to the variable $a, then convert the data type of $a to integer:


$a = "11.57"
$a = [int] $a

When you run these two commands and then echo back the value of $a you should get the following:


12

And if you run the GetType() method against $a you’ll see it now has the following data type:


IsPublic IsSerial Name
-------- -------- ----
True     True     Int32


Return to the VBScript to Windows PowerShell home page

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