# Strange float behaviors (integer division)

**URL:** <https://discourse.processing.org/t/strange-float-behaviors-integer-division/3867>\
**Category:** Beginners\
**Created:** [September 26, 2018, 3:45pm UTC](https://discourse.processing.org/t/strange-float-behaviors-integer-division/3867 "2018-09-26T15:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mloiz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mloiz/32/11462_2.png) [@mloiz](https://discourse.processing.org/u/mloiz)\
**Post date:** [September 26, 2018, 3:45pm UTC](https://discourse.processing.org/t/strange-float-behaviors-integer-division/3867/1 "2018-09-26T15:45:22Z")

</div>

i dont get this :  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/de363e36305e8d93ccdd408cbe5aad147b2aa3bd.png)

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

thank you

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 26, 2018, 3:51pm UTC](https://discourse.processing.org/t/strange-float-behaviors-integer-division/3867/2 "2018-09-26T15:51:41Z")

</div>

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:

```auto
1/2.0

```

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 27, 2018, 1:43am UTC](https://discourse.processing.org/t/strange-float-behaviors-integer-division/3867/3 "2018-09-27T01:43:09Z")

</div>

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

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

- **[Why does 2 / 5 = 0 instead of 0.4?](https://github.com/processing/processing/wiki/Troubleshooting#why-does-2--5--0-instead-of-04)**
