# Weird behaviour with mouseX and mouseY

**URL:** <https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618>\
**Category:** p5.js\
**Created:** [May 8, 2020, 7:52am UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618 "2020-05-08T07:52:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LinemanForTheCounty](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@LinemanForTheCounty](https://discourse.processing.org/u/LinemanForTheCounty)\
**Post date:** [May 8, 2020, 7:52am UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/1 "2020-05-08T07:52:35Z")

</div>

Whenever i retrieve mouseX and mouseY , mouseX returns as long decimal number and mouseY returns as a integer. (ex. [340.32472970811324, 350]).

This is quite annoying as it broke one of my functions.  
Does anyone have any idea why it is doing this?

---

<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:** [May 8, 2020, 7:54am UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/2 "2020-05-08T07:54:47Z")

</div>

Which OS?

Do you have a new mouse driver or mouse?

You can int() the value of course

---

<div class="post-metadata">

**Author:** ![LinemanForTheCounty](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@LinemanForTheCounty](https://discourse.processing.org/u/LinemanForTheCounty)\
**Post date:** [May 8, 2020, 7:58am UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/3 "2020-05-08T07:58:55Z")

</div>

> Which OS?

Ubuntu 18.04 , using chromium

> Do you have a new mouse driver or mouse?

mouse is the same one it has always been , the OS might have updated driver i am not sure.  
I did fix my issue with int() but it is just puzzling me why its a float for one and interger with the other.

---

<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:** [May 8, 2020, 11:14am UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/4 "2020-05-08T11:14:28Z")

</div>

Hello,

> [@LinemanForTheCounty](#):
>
> Whenever i retrieve mouseX and mouseY , mouseX returns as long decimal number and mouseY returns as a integer. (ex. [340.32472970811324, 350]).

Can you provide a small example of code to demonstrate this?

I will try it here.

`:)`

---

<div class="post-metadata">

**Author:** ![LinemanForTheCounty](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@LinemanForTheCounty](https://discourse.processing.org/u/LinemanForTheCounty)\
**Post date:** [May 8, 2020, 1:36pm UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/5 "2020-05-08T13:36:21Z")

</div>

I can just type [mouseX,mouseY] into the developer console, and i would get that result, it isnt limited to any part of the code

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [May 8, 2020, 9:37pm UTC](https://discourse.processing.org/t/weird-behaviour-with-mousex-and-mousey/20618/6 "2020-05-08T21:37:47Z")

</div>

[p5.js uses the underlying web API:s](https://github.com/processing/p5.js/blob/master/src/events/mouse.js#L463) to calculate the value of `mouseX` and `mouseY`. Those API:s returns a `double` floating-point value. In other words: this is expected behavior and works as intended.

> A `double` floating point value, as redefined by the CSSOM View Module. Originally, this property was defined as a `long` integer.

> **[MouseEvent: clientX property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX)**
>
> The clientX read-only property of the MouseEvent interface provides the horizontal coordinate within the application's viewport at which the event occurred (as opposed to the coordinate within the page).
