0

I got a strange behaviour in Powershell (ISE in this case).

Example Code:

[String]$stringVar = "\m/(o.0)\m/ "
[Double]$doubleVar1 = 2.5
[Double]$doubleVar2 = 3.5
[Double]$doubleVar3 = 4.5
[Double]$doubleVar4 = 5.5

write-host "2x $($stringVar * $doubleVar1)"
write-host "4x $($stringVar * $doubleVar2)"
write-host "4x $($stringVar * $doubleVar3)"
write-host "6x $($stringVar * $doubleVar4)"

Output:

2x \m/(o.0)\m/ \m/(o.0)\m/ 
4x \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ 
4x \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ 
6x \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/ \m/(o.0)\m/

It seems to me that powershell has some strange rounding behaviour. It looks like even decimals are beeing rounded down (or decimals are cut) and uneven decimals are rounded up. Is that normal behaviour?

What exactly is happening here?

Powershell (ISE) Version Info ($PSVersionTable):

Name                           Value                                                                                                                                                          
----                           -----                                                                                                                                                          
PSVersion                      5.1.15063.483                                                                                                                                                  
PSEdition                      Desktop                                                                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
BuildVersion                   10.0.15063.483                                                                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                                                                
WSManStackVersion              3.0                                                                                                                                                            
PSRemotingProtocolVersion      2.3                                                                                                                                                            
SerializationVersion           1.1.0.1 

Same behaviour in Powershell console.

EDIT: As @wOxxOm mentioned, this is normal .net4 rounding behaviour.

Follow this Stackoverflow thread

Akaino
  • 1,025
  • 6
  • 23

0 Answers0