locked
Number Comparison in Powershell RRS feed

  • Question

  • Hey Guys & Gals

    Do you know how I can compare two strings with two decimal points in it?

    For example. How can I compare $A and $B where $A = 1.1.1 and $B = 10.0.0 

    Obviously $B is greater than $A but how will the comparison work? The usual comparison doesn't seem to work here because of two decimal points 

    Tuesday, August 15, 2017 10:09 AM

Answers

  • In this case you can use the "version" comparison
    [Version]'1.1.1' -eq [Version]'10.0.0'
    [Version]'1.1.1' -gt [Version]'10.0.0'
    [Version]'1.1.1' -lt [Version]'10.0.0'


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by Bill_With_PS Thursday, August 17, 2017 5:37 PM
    Tuesday, August 15, 2017 10:28 AM

All replies

  • In this case you can use the "version" comparison
    [Version]'1.1.1' -eq [Version]'10.0.0'
    [Version]'1.1.1' -gt [Version]'10.0.0'
    [Version]'1.1.1' -lt [Version]'10.0.0'


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by Bill_With_PS Thursday, August 17, 2017 5:37 PM
    Tuesday, August 15, 2017 10:28 AM
  • Many Thanks

    Much appreciated

    Thursday, August 17, 2017 5:38 PM