# I have an error with divide (float issue)

**URL:** https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762
**Category:** Beginners
**Created:** [January 20, 2022, 10:05pm UTC](https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762 "2022-01-20T22:05:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![yalaniv](https://avatars.discourse-cdn.com/v4/letter/y/7993a0/32.png) [@yalaniv](https://discourse.processing.org/u/yalaniv)
#### Post date: [January 20, 2022, 10:05pm UTC](https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762/1 "2022-01-20T22:05:14Z")

</div>

I had a problem with a code, so I wrote a small one,  
and when I run it,  
it print 0.0, instead 0.2

What am I missing?

```auto
void setup(){
noLoop();
}

void draw(){
  float a = 2/10;
  println(a);
}

```

---

<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: [January 20, 2022, 10:14pm UTC](https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762/2 "2022-01-20T22:14:46Z")

</div>

> [@yalaniv](#):
>
> `float a = 2/10;`

Try 2/10.0;

Otherwise java sees it as integer  
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: [January 21, 2022, 9:07am UTC](https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762/3 "2022-01-21T09:07:18Z")

</div>

> [@yalaniv](#):
>
> `float a = 2/10;`

This is called integer division because both numbers, 2 and 10 are integers.

Cast you mind back to junior school when you only knew about whole numbers and the teacher asks you

> What do you get when you divide seven by two?

You would reply

> Three remainder one

In Integer division the remainder is ignored and only the first part is returned so  
`7/3` returns `2`

So two divided by ten is zero remainder two hence  
`2/10` returns `0`

NOTE: Integer division always returns an integer. In the expression  
`float a = 2/10;`  
The assignment operator (=) will take the integer 0 from the right hand side and store in a float variable on the left hand side. So when you print `a` you get `0.0` not `0`

The solution is to change one or both of the numbers to `float` as shown in previous post.

---

<div class="post-metadata">

### Author: ![yuvsaha123](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@yuvsaha123](https://discourse.processing.org/u/yuvsaha123)
#### Post date: [February 6, 2022, 11:48am UTC](https://discourse.processing.org/t/i-have-an-error-with-divide-float-issue/34762/4 "2022-02-06T11:48:46Z")

</div>

thanks for the awesome information.
