# Incorrect results when doing division with variables

**URL:** <https://discourse.processing.org/t/incorrect-results-when-doing-division-with-variables/3606>\
**Category:** Beginners\
**Created:** [September 17, 2018, 4:33pm UTC](https://discourse.processing.org/t/incorrect-results-when-doing-division-with-variables/3606 "2018-09-17T16:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cam](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@Cam](https://discourse.processing.org/u/Cam)\
**Post date:** [September 17, 2018, 4:33pm UTC](https://discourse.processing.org/t/incorrect-results-when-doing-division-with-variables/3606/1 "2018-09-17T16:33:12Z")

</div>

![03%20AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5ef268c29ace0cbbc0efc460e715ad9c155f5c94.png)

This code ^^

Returns this vv

width = 1000  
selImg.width = 255  
height = 1000  
selImg.height = 255  
((width / selImg.width) \* selImg.height) = 900  
((height / selImg.height) \* selImg.width) = 900

Obviously somethings going wrong with the math as 1000/255\*255 should result in 1000.

How do I fix this?

(I have console results but I can only use one image in each post)

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [September 17, 2018, 4:39pm UTC](https://discourse.processing.org/t/incorrect-results-when-doing-division-with-variables/3606/2 "2018-09-17T16:39:26Z")

</div>

Keep in mind that `int` values can only hold whole numbers.

So this:

```auto
int x = 3 / 2;
println(x);

```

Will print out `1` instead of `1.5`.

You can fix this by converting one of the numbers to `float` first:

```auto
float x = float(3) / 2;
println(x);

```

By the way, instead of posting an image of your output, please try to paste a [MCVE](https://stackoverflow.com/help/mcve) directly in your message. You should also try breaking your calculations down into multiple lines to understand what’s going on better.
