# Double to float

**URL:** <https://discourse.processing.org/t/double-to-float/12178>\
**Category:** Beginners\
**Created:** [June 19, 2019, 10:59am UTC](https://discourse.processing.org/t/double-to-float/12178 "2019-06-19T10:59:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![programmingNoob](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@programmingNoob](https://discourse.processing.org/u/programmingNoob)\
**Post date:** [June 19, 2019, 10:59am UTC](https://discourse.processing.org/t/double-to-float/12178/1 "2019-06-19T10:59:54Z")

</div>

I’m having issues with finding total velocity instead of having xVelocity and yVelocity. Would the correct strategy be to find the square root of the squares added, like with hypotenuses, or some other strategy? Here’s my code:

```auto
playerVel=(Math.sqrt(Math.pow(playerVelX,2))+Math.round(Math.pow(playerVelY,2))); 

```

I’ve done a lot of testing and keep getting the error message the double doesn’t match with float. I just need a total velocity, but can’t figure out why the square root doesn’t work.

---

<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:** [June 19, 2019, 11:44am UTC](https://discourse.processing.org/t/double-to-float/12178/2 "2019-06-19T11:44:21Z")

</div>

The Math class uses doubles throughout and Processing uses floats so I suggest you try

`playerVel = sqrt(playerVelX * playerVelX + playerVelY * playerVelY);`

this assumes all the variables are declared as `float`. If you want to use the Math class then try

`playerVel = (float)(Math.sqrt(playerVelX * playerVelX + playerVelY * playerVelY));`

Avoid using `pow` function to calculate the square, a simple multiplication is much better.

---

<div class="post-metadata">

**Author:** ![programmingNoob](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@programmingNoob](https://discourse.processing.org/u/programmingNoob)\
**Post date:** [June 19, 2019, 11:52am UTC](https://discourse.processing.org/t/double-to-float/12178/3 "2019-06-19T11:52:02Z")

</div>

Thank you so much! I’ll do that
