Take the 2-minute tour ×

I'm working with Android gestures and the onFling method. There are two float variables get passed velocityX and velocityY. Theses can either be 0.0, positive or negative. Obviously the 0.0 is easy to detect but how to I detect whether it's a positive or negative float.

I found some code for int and double but nothing relating to float specifically.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Have you tried < and >? These operators are used for that sort of thing...

share|improve this answer
Yeah was just wondering if there was a built in function. I say someone talking and exampling a build in thing for DOUBLE's –  James Krawczyk May 3 '12 at 0:21
Javadoc: docs.oracle.com/javase/7/docs/api/java/lang/Double.html The built-in function would be the <name>.compareTo(Double anotherDouble) –  anorton May 3 '12 at 0:23

Just compare with 0.0. like this:

var x = 0.01;
var y = -0.01;
if (x > 0.0) { /* positive */ }
if (y < 0.0) { /* negative */ }
share|improve this answer

Your Answer


