# Dividing two numbers results in int, even though it should be a float

**URL:** <https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794>\
**Category:** Beginners\
**Created:** [November 19, 2022, 8:31pm UTC](https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794 "2022-11-19T20:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalarila](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@Kalarila](https://discourse.processing.org/u/Kalarila)\
**Post date:** [November 19, 2022, 8:31pm UTC](https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794/1 "2022-11-19T20:31:27Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Ok, so I’m writing an image editing program and would like to get the aspect ratio of the image. So I declared a float variable called “aspectRatio” and as soon as the user uploads an image, it is put to picture.width/picture.height. If I now let my program print (picture.width + picture.height + aspectRatio), I for example get: 1515 700 2.0, even though the aspect ratio should be something like 2.164285714. It doesn’t matter what image I put in, I always get an even number. Is there a way I can get the real float number? (sorry if my english is bad :))

---

<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:** [November 19, 2022, 8:44pm UTC](https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794/2 "2022-11-19T20:44:26Z")

</div>

```auto

float aspectRatio = (float) picture.width / (float) picture.height; 

println(picture.width, picture.height ); 

println(aspectRatio);

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 19, 2022, 8:55pm UTC](https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794/3 "2022-11-19T20:55:52Z")

</div>

Hello @Kalarila ,

Some references to peruse:

- [Troubleshooting · processing/processing4 Wiki · GitHub](https://github.com/processing/processing4/wiki/Troubleshooting#why-does-2--5--0-instead-of-04)
- [Reference / Processing.org](https://processing.org/reference/floatconvert_.html)
- [https://codegym.cc/groups/posts/integer-division-java](https://codegym.cc/groups/posts/integer-division-java)
- [https://www.baeldung.com/java-integer-division-float-result](https://www.baeldung.com/java-integer-division-float-result)

`:)`

---

<div class="post-metadata">

**Author:** ![Kalarila](https://avatars.discourse-cdn.com/v4/letter/k/9d8465/32.png) [@Kalarila](https://discourse.processing.org/u/Kalarila)\
**Post date:** [November 19, 2022, 9:23pm UTC](https://discourse.processing.org/t/dividing-two-numbers-results-in-int-even-though-it-should-be-a-float/39794/4 "2022-11-19T21:23:28Z")

</div>

Oh thanks! I didn’t know this was possible 😃
