Flatlyn
Flatlyn

Reputation: 2050

Java Detect Whether Float Is Positive or Negative

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.

Upvotes: 1

Views: 6308

Answers (2)

clee
clee

Reputation: 11128

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 */ }

Upvotes: 3

apnorton
apnorton

Reputation: 2440

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

Upvotes: 5

Related Questions