Strange float behaviors (integer division)

i dont get this :
image

and if I said oi = PI/2 it does work …

thank you

Hi mloiz,

It is because of the way operation works.

Here you are dividing 2 integers so the result will also be an integer (even if you are storing it in a float).
More precisely 1/2 = 0.5 so you get 0.

Now with PI/2, you divide a float with an integer so you will get a float (to keep the maximum precision).

To solve your problem, try doing this:

1/2.0

By doing that, you are saying my divisor is a float number so divide an integer by a float.

5 Likes

Integer division is a common confusion when learning Processing – or Java.

There is also dedicated question for it on the wiki troubleshooting page:

1 Like