Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Entries from 2017-06-01 to 1 day

PowerShell does banker's rounding in type casting to int

Problem: PowerShell rounds 0.5 to 0 (banker’s rounding) in type casting to int. PS > @(-3.5,-2.5,-1.5,-0.5,0.5,1.5,2.5,3.5) | ForEach-Object { "{0} -> {1}" -F $_, [int]$_ } -3.5 -> -4 -2.5 -> -2 -1.5 -> -2 -0.5 -> 0 0.5 -> 0 1.5 -> 2 2.5 -…

Supported character encodings in Get-Content and Import-Csv (in PowerShell 2.0/4.0)

Tested in Windows 7 (Japanese). Import-Csv does not have -Encoding option in PowerShell 2.0. There are no option for UTF-32BE in PowerShell 2.0. (note: PowerShell ISE can handle UTF-32BE Files) Import-Csv does not support Unknown and Strin…