Comparison question string vs int
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-05-26T17:15:33Z
Indexed on
2010/05/26
17:21 UTC
Read the original article
Hit count: 196
powershell-v2.0
Can someone explain to me why these comparisons work they way the do. I had a bug in one of my scripts that took me a little bit to work through. I was using read-host and typing a number. It was storing it as a string.
Write-Host "(`'2`' -gt 9 ) = " ('2' -gt 9 )
Write-Host "(2 -gt 9 ) = " (2 -gt 9 )
Write-Host "(`'2`' -gt 10 ) = " ('2' -gt 10 )
If you are comparing a string to an Int does it use the Ascii value? If so why does the first one show $false, it should be $true.
Then how is it when you chage it to an int of 10 it because $true.
© Stack Overflow or respective owner