# Dividing a round number doesn't work. Dividing as a variable does?

**URL:** <https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862>\
**Category:** Beginners\
**Created:** [September 7, 2019, 10:01am UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862 "2019-09-07T10:01:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marinus](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Marinus](https://discourse.processing.org/u/Marinus)\
**Post date:** [September 7, 2019, 10:01am UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/1 "2019-09-07T10:01:03Z")

</div>

Hi, I am having a question why something doesn’t work one way, but it does the other way.

I was sketching something out in processing with this variable:

```auto
float k = 5 / 8;

```

It didn’t want to work. But when I did it like this:

```auto
float d = 8;
float n = 5;
float k = n / d;

```

Somehow it did work.

What is the difference?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 7, 2019, 11:14am UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/2 "2019-09-07T11:14:09Z")

</div>

need to force a floating point division.

```auto
float k = 5/8;
float l = 5/8.0;
float m = 5f/8;
println(k);
println(l);
println(m);

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 7, 2019, 12:46pm UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/3 "2019-09-07T12:46:30Z")

</div>

Because 5 and 8 are integers so 5 / 8 is _zero remainder five_ hence the answer is 0 it is called _integer division_. On the other hand `n / d` is dividing one float by another so you get `0.625`

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 7, 2019, 12:57pm UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/4 "2019-09-07T12:57:03Z")

</div>

I find this annoying too but it’s JAVA thing.

I produces errors that are hard to find.

This doesn’t work:

```auto
float k = 5 / 8;

```

But this does work (giving `0.625`) :

```auto
float k = 5 / 8.0;

```

Because one number is float (`8.0`).

Crazy but true.

Chrisir

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 7, 2019, 1:04pm UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/5 "2019-09-07T13:04:08Z")

</div>

> [@Chrisir](#):
>
> I find this annoying too but it’s JAVA thing.

Applies to all statically typed languages, not just Java

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 7, 2019, 1:05pm UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/6 "2019-09-07T13:05:57Z")

</div>

It’s like a implicit / tacit _conversion_ from a float result to integer and copying this result into a float variable. It’s confusing. 😉

---

<div class="post-metadata">

**Author:** ![Marinus](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Marinus](https://discourse.processing.org/u/Marinus)\
**Post date:** [September 7, 2019, 7:06pm UTC](https://discourse.processing.org/t/dividing-a-round-number-doesnt-work-dividing-as-a-variable-does/13862/7 "2019-09-07T19:06:15Z")

</div>

@quark and @Chrisir  
Thanks a lot for the explanations. In one of Daniel Shiffman’s videos I noticed that he also used the .0 trick to make it work but I didn’t know why he did that.

The above line was something I started doing in P5 which worked fine, but in Processing it didn’t and I couldn’t find out why!
