Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell 3.0 - Conditional operator wrong behaviour!??

$
0
0

Hi there! I am a VS C# programmer. Now I am learning PowerShell 3.0

During learning, I tried to make a block of codes for identifying input number's type. The code is:

#Starting of block

cls
$a = Read-Host 'Ínput'
if ($a -gt 0) {
Write-Host 'The input is positive'}
elseif ($a -eq 0) {
Write-Host 'The input is zero'}
else {
Write-Host 'The input is negative'}

#Ending of block

Unfortunately, the output is:

-----------------------------------

Ínput: 5
The input is positive

-----------------------------------

Ínput: 0
The input is zero

-----------------------------------

Ínput: -2
The input is positive

PS C:\Users\Admin> $a
-2

-----------------------------------

Ínput: .8
The input is negative

PS C:\Users\Razib> $a
.8

-----------------------------------

I am totally confused! I understand that I am missing some conditional operator's behavior pattern knowledge.

Can someone please help me out about it?

Regards.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>