# convert.ps1
# Sample showing converstion to int32, boolean, string and char
# Thomas Lee - tfl@psp.co.uk
# get number to convert
[system.double] $dNumber = 23.15
# convert to int16
[int32] $iNumber = [System.Convert]::ToInt32($dNumber)
"Converting $dnumber to an int32 = $inumber"
# convert to bool
[bool] $bNumber = [System.Convert]::ToBoolean($dNumber);
"Converting $dnumber to an Boolean = $bNumber"
# convert to string
[string] $strNumber = [System.Convert]::ToString($dNumber)
"Converting $dnumber to a String = $strNumber"
# convert a single char in the string to a char
[char] $chrNumber = [System.Convert]::ToChar($strNumber[0]);
"Converting 1st char of `"$strnumber`" to a char = $chrNumber"
#
This script produces the following output
PSH [C:\foo]: .\convert.ps1
Converting 23.15 to an int32 = 23
Converting 23.15 to an Boolean = True
Converting 23.15 to a String = 23.15
Converting 1st char of "23.15" to a char = 2