Code: Select all
^M::
x := 20
value := x/10
if(%value% = integer){
MsgBox, value is an integer
}else{
MsgBox, value is not an integer
}
Code: Select all
^M::
x := 20
value := x/10
if(%value% = integer){
MsgBox, value is an integer
}else{
MsgBox, value is not an integer
}
So, some number formatting might be required after using /, to get an integer.https://www.autohotkey.com/docs/Variables.htm#MulDiv wrote:True divide (/): Unlike EnvDiv, true division yields a floating point result even when both inputs are integers. For example, 3/2 yields 1.5 rather than 1, and 4/2 yields 2.0 rather than 2.
Code: Select all
if var is float
MsgBox, %var% is a floating point number.
else if var is integer
MsgBox, %var% is an integer.
if var is time
MsgBox, %var% is also a valid date-time.
Code: Select all
if (mod(20, 7) != 0)
msgbox % 20 / 7 " is not an integer."
if (mod(20, 5) = 0)
msgbox % 20 // 5 " is an integer."
Code: Select all
a:=5
b:=10
c:=(a+b)
msgbox,C=%c%
Code: Select all
;- integer=True if Var is non-empty and contains a purely numeric string (decimal or hexadecimal) without a decimal point.
;- Leading and trailing spaces and tabs are allowed. The string may start with a plus or minus sign.
;SetFormat, float, 0.0
SetFormat, float, 0.2
x1:=15.25
x2:=floor(x1)
x3:=20
msgbox,X1=%x1%`nX2=%x2%`nX3=%x3%
if x1 is integer
msgbox,X1=%x1% is integer
if x2 is integer
msgbox,X2=%x2% is integer ;- without a decimal point
if x3 is integer
msgbox,X3=%x3% is integer ;- without a decimal point
return
Code: Select all
x := 20
value := x/10
Code: Select all
a:=20
b:=10
c:=(a*b) ;- 200
d:=(a/b) ;- 2.000000 ( how can see = 2 ( ? ) ) , maybe use floor if 000000 after decimal point
msgbox,C=%c%`nD=%d%
return
Code: Select all
x1:=315.55
;----------
if (x1 is integer) ;- don't use bracket
MsgBox,X1a=%x1% IS an integer (WRONG)
else
MsgBox,X1a=%x1% NOT an integer
if x1 is integer ;- correct
MsgBox,X1b=%x1% IS an integer
else
MsgBox,X1b=%x1% NOT an integer (CORRECT)
return
Oh, drat, my bad. I've messed up this whole thread! Should I just delete my posts here, do you think?
Code: Select all
Loop
{
x := A_Index
value := x/10
flor := x//10
if (value = flor)
MsgBox, %value% is an integer
}
until x=21
Code: Select all
;- if division , I see result >> 2.000000 ( I want see = 2 )
a:=20,b:=10
c:=(a*b) ;- 200
d:=(a/b) ;- 2.000000 ( how I can see = 2 ( ? ) ) , maybe use floor if 000000 after decimal point
stringsplit,k,d,`.
if (k2="000000")
d:=k1 ;- 2 , so this is an integer
msgbox,C=%c%`nD=%d%
a:=20,b:=7
c:=(a*b) ;- 140
d:=(a/b) ;- 2.857143 << this NOT integer but the correct result
e:=(a//b) ;- 2 << this IS integer but not correct result
msgbox,C=%c%`nD=%d%`nE=%e%
return
No, please don't delete/empty them in the future! That's against the forum rules.
OK, thanks. Too late! I didn't think to check the rules. Even so, I think the potential confusion my attempts might have caused readers were probably worse than any interruption of flow. All that's left is people quoting my mistakes and correcting them. And (hopefully) my correct solution.gregster wrote: ↑11 May 2020, 13:50No, please don't delete/empty them in the future! That's against the forum rules.
Others might have reacted to your posts and now the context is broken.
People are here to learn - you are allowed to make mistakes, please allow others to learn from them... thank you!
Yes. Thereforegarry wrote: ↑11 May 2020, 13:36;- integer=True if Var is non-empty and contains a purely numeric string (decimal or hexadecimal) without a decimal point.
;- Leading and trailing spaces and tabs are allowed. The string may start with a plus or minus sign.
If division , I see result >> 2.000000 ( I want see = 2 ) , so it's never integer ( because decimal point )
How can remove decimal point and zeros , so the variable 'd' is integer ?
Code: Select all
;- if division , I see result >> 2.000000 ( I want see = 2 ) a:=20,b:=10 c:=(a*b) ;- 200 d:=(a/b) ;- 2.000000 ( how I can see = 2 ( ? ) ) , maybe use floor if 000000 after decimal point stringsplit,k,d,`. if (k2="000000") d:=k1 ;- 2 , so this is an integer msgbox,C=%c%`nD=%d% a:=20,b:=7 c:=(a*b) ;- 140 d:=(a/b) ;- 2.857143 << this NOT integer but the correct result e:=(a//b) ;- 2 << this IS integer but not correct result msgbox,C=%c%`nD=%d%`nE=%e% return
Code: Select all
Loop
{
x := A_Index
value := x/7
flor := x//7
if (value = flor)
MsgBox, %value% is an integer
else
MsgBox, %value% is not an integer
}
until x=21
Code: Select all
a:=20 , b:=10
;a:=20 , b:=7
c:=a/b
d:=a//b
msgbox,C=%c%`nD=%d%
if (c=d) ;- C= 2.000000 and D= 2 ( they are equal ) in first example it's an integer
MsgBox, D=%d% IS an integer ( equal to C )
else
MsgBox, C=%c% NOT an integer
return