What is INT ?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 9 months ago.

  • Author
    Posts
  • #23149
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    I'm new to powershell and just watched the excellent "Getting Started with PowerShell 3.0 Jump Start" videos. Trying to get my head around things.

    The command below, in the second line, after -as what is the [INT] ? What does that mean/do ?

    Get-wmiobject win32_logicaldisk -filter "DeviceID='c:'" |
    select @{n='FreeGb';e={$_.freespace / 1gb -as [int]}}

    Thanks,

  • #23150
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    [int] is a .NET type literal; in this case, it's for the 32-bit signed Integer type ([int] is a shorcut for [System.Int32]). It can represent any whole number (no decimal points or fractions) between -2147483648 and 2147483647.

    In this case, what that's doing is taking the result of ($_.FreeSpace / 1GB), which will likely contain a large number of decimal places, and casting it to a whole number. Whether this rounds the number or just truncates the decimal portion depends on what language you're using. In the case of PowerShell, it rounds the number (and uses banker's rounding for x.5 values; they get rounded to the nearest even number, so 0.5 becomes 0 and 1.5 becomes 2.)

You must be logged in to reply to this topic.