5
Var first
Var second
Section
   Strcpy $first "1.0"
   Strcpy $Second "2.1"
   ${If} $second > $first
     MessageBox MB_OK "Grater"
   ${Else}
     MessageBox MB_OK "Smaller"
   ${EndIf}
SectionEnd

I have written the above code but it is showing me result as smaller. And how to compare a integer or double value coming from a text file with a predefined double or integer value?

Vishal Patil
  • 195
  • 2
  • 13

2 Answers2

5

Using LogicLib, You may compare two integers like this:

Var first
Var second
Section
   StrCpy $first 1
   StrCpy $Second 2
   ${If} $second > $first
     MessageBox MB_OK "Grater"
   ${Else}
     MessageBox MB_OK "Smaller"
   ${EndIf}
SectionEnd

with capital C in StrCpy. Also try removing quotes (") from numbers to make them integers.

Another way would be this:

Push $first
Push $Second
StrCpy $first 8
StrCpy $Second 2

IntCmp $first $Second Equal Val1Less Val1More

Equal:
    DetailPrint "$first = $Second"
    Goto End
Val1Less:
    DetailPrint "$first < $Second"
    Goto End
Val1More:
    DetailPrint "$first > $Second"
    Goto End
End:

Pop $Second
Pop $first
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
1

NSIS does not support floating point numbers in the basic instructions, you need to use the Math plugin that is part of the default install...

Anders
  • 97,548
  • 12
  • 110
  • 164