Marsman
Marsman

Reputation: 825

How Do You Compare a Range of Float Decimal Numbers in xCode?

This code does not work. Any suggestions?

float tempNum = 0.590000;
int temporary;
if (tempNum >= 0.590000 && tempNum <= 0.610000){
    temporary = 15;
}
// temporary yields zero

Upvotes: 0

Views: 611

Answers (1)

Daniel
Daniel

Reputation: 577

So:

By default 0.590000 is a DOUBLE

So float tempNum = 0.59000 causes a cast.

To prove this try:

float tempNum = 0.590000f;
int temporary;
if (tempNum >= 0.590000f && tempNum <= 0.610000f){
    temporary = 15;
}

So, remember that:

aaa.aaa is a DOUBLE

aaa.aaaf is FLOAT

Upvotes: 1

Related Questions