Skip to content
⌘ NSIS Forum Archive

Numeric calculations including fractions?

5 posts

cchian#

Numeric calculations including fractions?

I am trying to divide a number by another one which is not an integer (ie 1234 divided by 56.789). Is this possible? So far I have only been able to get the answer as an integer (using IntOp).
CodeSquid#
Well, try the following:

StrCpy $1 33
StrCpy $2 88
; 33/88=0.375
IntOp $1 $1 * 1000
IntOp $3 $1 / $2 ; $3 is now 375

; Now try to output $3:
IntOp $4 $3 / 1000
IntOp $5 $3 % 1000
MessageBox MB_OK "$4.$5" ; output the number, in this case 0.375

Exchange 1000 with a greater value if you need more digits after the .
cchian#
Thanks for your suggestion. What I wanted to do was to divide a number (integer) by something that is not an integer (ie 5.789). In your example, if I assign 5.789 to $2, the calculation with IntOp would ignore anything after the decimal point. It will be like 33/5 instead of 33/5.789