precision problem?

robrobrob

Registered
I am having some problems with xcode doing some simple numerical tasks.

I have a float set equal to 4.

I later need to make a decision that hinges on the value of this float.

I specifically want to do something if the variable equals 4.

I write an if statement, and it never gets to the equals 4 condition.

If I ask it to act if the value is between 3.99 and 4.01 it is fine, but this seems like a bad way to have to write code.

Also, I later need to assign the value of my float to an integer. My float is set as 4, but if I print the float typecast as an int, I get 3. I thought typecasting a float to an int would truncate it to the integral part of the number. How can this result in 3?

If anyone has anthing enlightening to say on these topics, I am eager to hear it.

rob
 
Back
Top