两个字符串之间的比较不起作用

问题描述 投票:0回答:1

我在比较两个版本时遇到问题。

PS C:\Windows\system32> $soft.DisplayVersion -lt "124.0"
False

我希望它返回 True,因为 $soft.DisplayVersion 的值是:

PS C:\Windows\system32> $soft.DisplayVersion
95.0

对象类型:

PS C:\Windows\system32> $soft.DisplayVersion.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                                            
-------- -------- ----                                     --------                                                                                                                                                            
True     True     String  

我也尝试过这个:

PS C:\Windows\system32> $soft.DisplayVersion -lt 124.0
False

我不知道它是否有帮助,但 $soft.DisplayVersion 来自此:

Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -match "Mozilla Firefox" 

如果您需要额外信息来理解我的问题,请告诉我。

string powershell if-statement
1个回答
0
投票

我终于使用了这个语法:

[decimal]$soft.DisplayVersion -lt 124.0
True
© www.soinside.com 2019 - 2024. All rights reserved.