Code: Select all
a.f=30
b.a=4
Debug 30/4
Debug a/b
(Does that make sence ? I'm getting confused now.)
Code: Select all
a.f=30
b.a=4
Debug 30/4
Debug a/b
Force it (add .0)Joris wrote:Why is Debug 30/4 equal to 7 instead of 7.5 ?It makes using a float always necassary even when I just wonna be able to detect if a division is integer or not ?Code: Select all
a.f=30 b.a=4 Debug 30/4 Debug a/b
(Does that make sence ? I'm getting confused now.)
Code: Select all
a.f=30
b.a=4
Debug 30/4 ; (show 7)
Debug 30/4.0 ; (show 7.5)
Debug a/b ; (equal 7.5)
Code: Select all
If Int(30 / 4.0) = 30 / 4.0
Debug "Integer"
Else
Debug "Not integer"
EndIf
Code: Select all
a.a=30
b.a=4
Debug a/b
Debug 0.0 + a/b
Code: Select all
a.a = 30
b.a = 4
If Mod(a, b)
Debug "not integer"
EndIf
To avoid this, simply cast the output:Joris wrote:Why is Debug 30/4 equal to 7 instead of 7.5?
Code: Select all
Debug StrF(28/4) ; = 7
Debug StrF(30/4) ; = 7.5
An alternative approach:Joris wrote:...I just wonna be able to detect if a division is integer or not?
Code: Select all
If Mod(28, 4)
Debug "Not Integer"
Else
Debug "Integer"
EndIf
; = Integer
If Mod(30, 4)
Debug "Not Integer"
Else
Debug "Integer"
EndIf
; = Not Integer
A strange conclusion, to me.In calculations, PB will use the variable type that matches the used variables.
That means if you have a division of just intenger, the result will be an integer.
It's not really a trick, this is how languages usually works.Joris wrote: Still confusing the need of using those tricks to get a correct value debugged, but yeah...