Weird Division Bug

Monkey Forums/Monkey Programming/Weird Division Bug

Aman(Posted 2011) [#1]
I did not put this in the bug section cause I it might be intended to act like this to prevent something from going wrong or for other reason.

When I try to do this division I always get 1
scale=DeviceWidth()/img.Width()

But If I do this, it works fine:
w=DeviceWidth()
scale=w/img.Width()

I was just wondering why is this happening?


muddy_shoes(Posted 2011) [#2]
What are the definitions of w and scale?


Aman(Posted 2011) [#3]
floats
I also tried to do is:
DrawText "scale= "+DeviceWidth()/img.Width(),x,y

with the same result


muddy_shoes(Posted 2011) [#4]
Right, so:

scale=DeviceWidth()/img.Width()

That's Float = Int/Int. In other words, you're doing an integer division and the result will be an integer which is then assigned to a float.

w=DeviceWidth()
scale=w/img.Width()

That's Float = Float/Int, so the division produces a float result.


Aman(Posted 2011) [#5]
LOL. I feel stupid not to notice that. Thanks