Comparison question string vs int
- by Mike
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.