在排序百分比数字时遇到了一个小问题。我只是写了一个简单的脚本来测试:
function get-percent{
$obj1 = New-Object PSObject
$percentUsed1="{0:P0}" -f (100/100)
$obj1 | Add-Member -membertype NoteProperty -Name 'Percent' -Value $percentUsed1
$obj2 = New-Object PSObject
$percentUsed2="{0:P0}" -f (99/100)
$obj2 | Add-Member -membertype NoteProperty -Name 'Percent' -Value $percentUsed2
$obj3 = New-Object PSObject
$percentUsed3="{0:P0}" -f (8/100)
$obj3 | Add-Member -membertype NoteProperty -Name 'Percent' -Value $percentUsed3
$obj4 = New-Object PSObject
$percentUsed4="{0:P0}" -f (70/100)
$obj4 | Add-Member -membertype NoteProperty -Name 'Percent' -Value $percentUsed4
write $obj1
write $obj2
write $obj3
write $obj4
}
get-percent | sort-object 'Percent' -descending |ft
这是我得到的:
百分
99%
8%
70%
100%
通常,我应该有:100%、99%、70%……有什么想法吗?谢谢。